Is there a way to continue the exception in C #?

When an unexpected exception appears in your program (in the debugger). Sometimes you just want to skip it, because killing the program at this moment is more dangerous than continuing. Or you just want to continue as you are more interested in another error / error

Is there a / compilerflag / secretswitch option to enable this?

I understand that exceptions should be allowed immediately, but there are scenarios (as I described) where you just need to skip it for time

+4
source share
8 answers

You cannot do this without the corresponding catch block in your code, no. However, I don’t remember ever wanting to do this: if an exception occurs that your code does not know how to handle correctly, why do you want to continue? At this moment you are in poor condition - the continuation will be dangerous.

Can you give an example of why you want to continue working in a debugger session, but not in production code?

+6
source

Use a try-catch block, and do nothing about the exception when catching.

+2
source

Exceptions in C # do not resume, but events are how excluded exceptions are usually implemented: undo events. See also this question .

+2
source

If you entered the debugger, right-click on the line you want to continue and select: Install the following expression ... but use it at your own risk!

+1
source

When navigating through code in debug mode, you may skip executing instructions that cause an unwanted exception. But if the exception is already thrown and you don't have try / catch, it will propagate.

+1
source

See the Exception Handling Application Block and related documentation. It contains recommendations for handling application exceptions, and there is a lot of framework code for you, i.e. Logging.

0
source

If you want to know which exception you want to allow. then you can do it below

try { // your functionality } catch(Exception ex) { // Catch only the exceptions you need to point out } finally { //do what you want to complete with this function. } 
0
source

I assume that skipping means that you want your program to continue to work after the exception. This, of course, is possible by catching an exception when using the try-catch block.

If the exception is not a traffic jam (for example, some key variable is not initialized after the exception, and you cannot continue working), it is recommended that you at least register it before continuing. Of course putting

catch (exception e) {}

everywhere in your source will not lead to a stable application;)

If your problem is more related to the debugger (you do not want the debugger to stop on every exception thrown), then in VS there is a place where you can change this:

From the Debug menu, select Exceptions . You will see all the possible exceptions, and you can configure their behavior during the throw or not be handled by the user.

0
source

All Articles