is there a way to continue an exception in C#?

Toad picture Toad · Dec 16, 2009 · Viewed 7.7k times · Source

When an unexpected exception occurs in your program (in the debugger). Sometimes you just want to skip it since killing the program at that point is more harmful than continuing. Or you just want to continue since you were more interested in another error/bug

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

I understand exceptions should be resolved right away, but there are scenarios (like I described) where one just wants to skip it for the time-being

Answer

Jon Skeet picture Jon Skeet · Dec 16, 2009

You can't do this without an appropriate catch block in your code, no. However, I can't remember ever wanting to do this: if an exception occurs which your code doesn't know how to genuinely handle, why would you want to continue? You're in a bad state at that point - continuing would be dangerous.

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