c# - 如何捕获 .NET 应用程序中的所有异常/崩溃

标签 c# .net exception-handling

<分区>

Possible Duplicate:
.NET - What’s the best way to implement a “catch all exceptions handler”

我有一个 .NET 控制台应用程序崩溃并向用户显示一条消息。 我所有的代码都在 try{<code>} catch(Exception e){<stuff>} 中 block ,但偶尔仍会显示错误。

在 Win32 应用程序中,您可以通过安装各种异常处理程序来捕获所有可能的异常/崩溃:

/* C++ exc handlers */
_set_se_translator
SetUnhandledExceptionFilter
_set_purecall_handler
set_terminate
set_unexpected
_set_invalid_parameter_handler

在 .NET 世界中有什么等价物可以让我处理/记录/安静所有可能的错误情况?

最佳答案

您可以向 AppDomain.UnhandledException 事件添加一个事件处理程序,它会在异常被抛出但未被捕获时被调用。

关于c# - 如何捕获 .NET 应用程序中的所有异常/崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/82483/

相关文章:

c# - 2 列范围之间的 Linq 值

c# - .dll's are missing after rebuild/clean-build 解决方案

c# - 使用另一个字典的键按值对字典进行排序

.net - 相互通知模式

.net - 定义事件处理程序

python - 在变量中使用 except 和存储错误

c# - 将 DataGrid 的 ItemsSource 绑定(bind)到列表

c# - Linq to Entities - NotSupportedException - 动态类型 - string.Format

windows - 异常处理

PHP 5.5 并尝试......终于