简体   繁体   English

在ASP.NET MVC应用程序的C#中抑制运行时异常

[英]Suppressing runtime exceptions in C# for ASP.NET MVC application

How do I suppress an exception in C#? 如何在C#中抑制异常? I do not want to enclose it in a try-catch block with an empty catch block - that would defeat the purpose. 我不想将其包含在try-catch块中,并保留一个空的catch块-这样会破坏目的。 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. 我有一个自定义的Application_Error处理程序/侦听器,用于检查HttpException ,我宁愿它自动运行,也不像Visual Studio提示您运行HttpException ,我必须在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. 当我的代码中发生HttpException时,Visual Studio中将打开一个调试异常对话框,并且我的项目暂停。 Then when I click Continue my Application_Error is able to handle it. 然后,当我单击继续时,我的Application_Error能够处理它。 I would like it to automatically continue. 我希望它自动继续。

In response to Simon's answer, I do not want exception handling turned off globally. 为响应Simon的回答,我不希望全局关闭异常处理。

Two Things: 两件事情:

  1. For production: Use ELMAH . 生产:使用ELMAH Use ELMAH and any Yellow Screen of Death errors get logged. 使用ELMAH,所有黄色死亡屏幕错误都会被记录。

  2. For Development and YSOD: See this Stack Overflow question that covers your specific issue: 对于开发和YSOD:请参阅此Stack Overflow问题,其中涉及您的特定问题:

Catching Exceptions within ASPX and ASCX Pages 在ASPX和ASCX页面中捕获异常

您可以通过转到Debug-> Exceptions更改导致IDE中断的异常,并关闭相关异常的Thrown和User-unhandled选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM