views:

580

answers:

2

How do I suppress an exception in C#? I do not want to enclose it in a try-catch block with an empty catch block - that would defeat the purpose. I have a custom Application_Error handler/listener that checks for HttpException and I would much rather that run automatically than being prompted by Visual Studio for a HttpException and I would have to click Continue in the IDE.

By suppression, I mean to stop this from happening. when the HttpException occurs in my code, a debug exception dialog opens in Visual Studio and my project pauses. Then when I click Continue my Application_Error is able to handle it. I would like it to automatically continue.

In response to Simon's answer, I do not want exception handling turned off globally.

A: 

Two Things:

  1. For production: Use ELMAH. Use ELMAH and any Yellow Screen of Death errors get logged.

  2. For Development and YSOD: See this Stack Overflow question that covers your specific issue:

Catching Exceptions within ASPX and ASCX Pages

George Stocker
That does not answer my question. I am using Application_Error to catch my 404 and it does *not* show a yellow screen of death.
Daniel A. White
No, but if you have an unhandled exception, ELMAH Will log all of them, even if they are surpressed from the end user.
George Stocker
A: 

You can change which exceptions cause the IDE to break by going to Debug -> Exceptions and turn off the Thrown and User-unhandled options for the relevant exceptions.

Simon Steele
I do not want to turn this off globally.
Daniel A. White