Best practice for handling exceptions that are thrown inside a catch block in a stream. (.NETWORK)

How do you feel about exception handling when executing a thread? More specifically, what if an exception is thrown inside a catch block in a try-catch clause? And what happens to the thread if the exception is unhandled?

+5
source share
6 answers

What is your opinion on exception handling when executing a thread?

You should handle exceptions whenever possible, and whenever you expect exceptions. Clarification: I completely agree with John that you should not handle exceptions everywhere - only where you can do something with them. However, you should never allow an exception to go through without processing in the thread, as this can cause serious problems. Have a root exception handler and let your thread do it gracefully (after registering the problem, etc.)

In particular, what if a thread is thrown inside a catch block of a try-catch clause?

You mean: What if an exception is thrown in a catch block? Well, then it is not processed by the current try-catch block. It’s better not to put too much processing in the catch block to avoid this situation as much as possible.

And what happens to the stream if the stream is not processed?

: , ? .

:

UnhandledException AppDomain. :

AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
+7

ren, , , , , .

, . - , , . , .

try {
    // ..
} catch (Exception ex) {
    Console.WriteLine(ex.Message);
}

. -, , . -, , , .

+7

UnhandledException AppDomain. , :

AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

+4

.

, (, , ), , appdomain, .

+1

, , . , , , , , .

- catch, , , catch try.

0

.net , catch finally, . , .net , "catch" , , . ,.net ; , ​​, , , .

Therefore, you have a choice: suppress the new exception and allow the old one to propagate, let the new one propagate and lose the old one, or create a composite exception object that can only be processed by code that knows look for it. None of them are a particularly pleasant choice. Which one of them will best depend on an understanding of the conditions that are different types of exceptions, and what call code will expect them to.

0
source

All Articles