views:

227

answers:

6

Is there a possibility to deactivate / activate all try catch blocks in the whole project as easy as clicking a button?

Environment: VS 2008 with C# as language.

+8  A: 

No, there isn't. Why would there be? What are you trying to achieve?

If you want to break as soon as a particular type of exception is thrown, you can get Visual Studio to do that (Debug -> Exceptions; select the exception type you're interested in and check the "Thrown" box). I'm finding it hard to think of any other reason why you'd want to turn off error handling...

EDIT: One point I hadn't thought about before - which version of Visual Studio are you using? If it's Express, I'm not sure whether this is supported - I can check, but it'll take a little while. Let me know if I need to...

Jon Skeet
+1  A: 

If you want to break as soon as a particular type of exception is thrown, you can get Visual Studio to do that.

This is what I want. How can I do that?

+1  A: 

If you want to do in the IDE, Debug -> Exceptions is the dialog where you can ask the IDE to break when a specific/category/all exceptions are thrown.

shahkalpesh
+5  A: 

To catch exceptions the moment they're thrown ("first-chance exceptions" in Win32 parlance), go to Debug, Exceptions..., and check the box Thrown for Common Language Runtime Exceptions.

Frank Krueger
A: 

You can change the way Visual Studio breaks when an exception occurs. By default, it breaks on unhandled exceptions. If you go to menu Debug > Exceptions, you can uncheck Common Language Runtime Exceptions and make other changes in the IDE's behavior when exceptions occur. For example, you can have it break on only one kind of exception; there's a long list there.

I have done this on rare occasions when trying to debug.

DOK
+1  A: 

I need it when debugging. I don't want the catch block to handle the exception but that VS breaks into the code as if the try catch block was not there. At the moment I comment the try catch blocks but it takes to long.

Sorry if it wasn't clear enough before, I hope it is now.

I'm using VS 2008 Prof.