How to handle exceptions in large base codes

I have a large C # code base. From time to time it seems rather difficult, and I was wondering if there is a quick way to improve the search and diagnosis of problems that occur on client PCs.

The most pressing issue is that exceptions occur in the software, are caught, and even passed to me. The problem is that by the time they are discovered, the original reason for the exception is lost.

those. If an exception was found in a particular method, but this method calls 20 other methods, and these methods each will call 20 other methods. You get an image, the link exception cannot be determined, especially if it happened on the client machine.

Currently, I have found some places where, I think, errors are more common and wrap them directly in their own catch catch blocks. Is this the only solution? I could be here a long time.

I don’t care that an exception will reduce the current process (this is just the thread, not the main application), but I don’t care that the exceptions are returned and do not help to fix the problem.

Any ideas?

I am well aware that I probably ask a question that sounds stupid and may not have a direct answer. Still, the discussion would be good.

+3
source share
1 answer

, , . - :

try
{
    //...
}
catch ( Exception e )
{
    //do stuff with exception
    throw e;
}

:

try
{
    //...
}
catch ( Exception )
{
    //do stuff with exception
    throw;
}

, - . , , , . , , , , .

+3

Source: https://habr.com/ru/post/1745916/


All Articles