C# 控制台应用程序 - 防止默认异常对话框
我有一个带有单个 AppDomain 的简单应用程序,该应用程序定期在服务器上启动。 有时应用程序中会出现未处理的异常,并且会弹出默认的中止/重试/忽略对话框。 我需要以某种方式阻止 edialog 显示并仅在 StrErr 上输出异常并关闭应用程序。 所以我用 try-catch 语句将 main 方法中的所有代码括起来,但它根本没有帮助 - 有时仍然会显示异常对话框。
Main() 代码如下所示:
try
{
RunApplication();
}
catch (Exception exc)
{
Console.Error.WriteLine(exc.ToString());
Console.Error.WriteLine(exc.StackTrace);
if (exc.InnerException != null)
{
Console.Error.WriteLine(exc.InnerException.ToString());
Console.Error.WriteLine(exc.InnerException.StackTrace);
}
Environment.Exit(666);
}
这个 try-catch 子句应该捕获所有未处理的异常,并且据我所知,异常对话框永远不应该弹出。 我错过了什么吗? 或者服务器上是否有任何设置(注册表等)来控制与异常对话框/应用程序错误代码相关的某些特殊行为?
I have simple application with single AppDomain which is periodicaly launched on a server. Sometimes unhandled exception occurs in the aplication and default abort/retry/ignore dialog pops up. I need to somehow prevent the edialog from showing and just output the exception on StrErr and close the application. So I enclosed all the code in main method with try-catch statement, but it didn't help at all - the exception dialog is still shown sometimes.
The Main() code looks like this:
try
{
RunApplication();
}
catch (Exception exc)
{
Console.Error.WriteLine(exc.ToString());
Console.Error.WriteLine(exc.StackTrace);
if (exc.InnerException != null)
{
Console.Error.WriteLine(exc.InnerException.ToString());
Console.Error.WriteLine(exc.InnerException.StackTrace);
}
Environment.Exit(666);
}
This try-catch clause shoud catch all unhandled exceptions and the exception dialog should never popup AFAIK. Am I missing something? Or is there any setting (registry etc) on the server which controls some special behaviour related to the exception dialog/application error code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在应用程序域中订阅未处理的异常事件。
There's an unhandled exception event you can subscribe to in the application domain.
您是否考虑过您的 catch 子句可能引发异常的可能性?
您是否在主应用程序中生成线程?
Have you considered the possibility that your catch clause may be throwing exceptions?
Do you spawn threads in your main app?