全局异常处理程序 [英] Global Exception Handler
本文介绍了全局异常处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写了一个在Windows上作为批处理作业运行的控制台应用程序
2000 Server。每隔一段时间我就会向
控制台抛出异常。有没有办法可以创建一个全局处理程序,可以捕获这个
异常并阻止应用程序锁定?我在所有数据库和文件写入调用中执行尝试
catch语句,因此我不确定
来自哪里。
非常感谢任何建议或建议。
谢谢,
马特
I have written a console application that runs as a batch job on Windows
2000 Server. Every once in a while I am getting an exception thrown to the
console. Is there a way I can create a global handler that can catch this
exception and prevent the application from locking up? I am performing try
catch statements at all database and file write calls so I am unsure where
it is coming from.
Any suggestions or recommendations are greatly appreciated.
Thanks,
Matt
推荐答案
HI,
异常是什么意思?
尝试使用AppDomain.UnHandledException和/或AppDomain.ThreadException
欢呼,
-
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
佛罗里达州交通局
" Matt" < MD ***** @ sorvive.DONT-SEND-SPAM.com>在消息中写道
新闻:Oz ************** @ TK2MSFTNGP09.phx.gbl ...
What does the exception says?
Try to use AppDomain.UnHandledException and/or AppDomain.ThreadException
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Matt" <md*****@sorvive.DONT-SEND-SPAM.com> wrote in message
news:Oz**************@TK2MSFTNGP09.phx.gbl...
我写了一个控制台在Windows
2000 Server上作为批处理作业运行的应用程序。每隔一段时间我就会向
控制台抛出异常。有没有办法可以创建一个全局处理程序,可以捕获此异常并阻止应用程序锁定?我在所有数据库和文件写入调用中执行尝试
catch语句,所以我不确定它来自哪里。
非常感谢任何建议或建议。
谢谢,
Matt
I have written a console application that runs as a batch job on Windows
2000 Server. Every once in a while I am getting an exception thrown to the
console. Is there a way I can create a global handler that can catch this
exception and prevent the application from locking up? I am performing try
catch statements at all database and file write calls so I am unsure where
it is coming from.
Any suggestions or recommendations are greatly appreciated.
Thanks,
Matt
那是'AppDomain.UnhandledException和Application.ThreadException 。
That''s AppDomain.UnhandledException and Application.ThreadException.
Ignacio,
实际上我已经设置了这样的事件处理程序。消息是JIT调试失败,出现以下错误:0x800405a6。
文档说:
JIT调试失败,出现以下错误:0x800405a6如果您尝试此错误在没有用户登录控制台的机器上进行实时调试。因此,没有会话显示即时调试对话框。
要解决此问题,请登录计算机。
我在调度程序下运行此应用程序,所以我不确定为什么我会这样做使用此应用程序,但我的其他.Net应用程序都没有得到这个。
在main()中我有:
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException + = new EventHandler(LastChanceHandler);
然后方法:
void LastChanceHandler( object sender,UnhandledExceptionEventArgs args)
{
Exception ex =((Exception)(args.ExceptionObject));
Logging.WriteLine(" ****** LastChanceHandler ******");
Logging.WriteLine(" ExceptionType:{0}",ex.GetType()。Name);
Logging.WriteLine(" HelpLine:{0}",ex.HelpLink);
Logging.WriteLine(" Message:{0}",ex.Message);
Logging.WriteLine(" Source:{0}",ex.Source);
Logging.WriteLine(" StackTrace:{0}",ex.StackTrace);
Logging.WriteLine(" TargetSite:{0}",ex.TargetSite);
string indent ="" + Microsoft.VisualBasic.Chr(9)+"" ;;
Exception ie = ex;
while(!((ie.InnerException == null))){
ie = ie.InnerException;
Logging.WriteLine(缩进+" ******内部例外******");
Logging.WriteLine(indent +" ExceptionType:{0}",ie.GetType()。Name);
Logging.WriteLine(缩进+" HelpLine:{0}",ie.HelpLink);
Logging.WriteLine(缩进+"消息:{0}",ie.Message);
Logging.WriteLine(缩进+"来源:{0}",ie.Source);
Logging.WriteLine(缩进+" StackTrace:{0}",ie.StackTrace);
Logging.WriteLine(缩进+" TargetSite:{0}",ie.TargetSite);
缩进+ ="" + Microsoft.VisualBasic.Chr(9)+"" ;;
}
}
关于如何捕捉错误的任何想法???
谢谢,
Matt
Ignacio Machin(.NET / C#MVP)" < ignacio.machin AT dot.state.fl.us>在留言新闻中写道:OC ************** @ TK2MSFTNGP10.phx.gbl ...
Ignacio,
Actually I already have an event handler set up like that. The message is JIT Debugging Failed with the following error: 0x800405a6.
Documentation says:
JIT Debugging failed with the following error: 0x800405a6This error occurs if you attempt to do Just-In-Time debugging on a machine where there is no user logged onto the console. As a result, there is no session in which to display the Just-In-Time debugging dialog box.
To fix this problem, log onto the machine.
I am running this application under the scheduler so I am unsure why I get this with this application but yet none of my other .Net applications get this.
In main() I have:
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new EventHandler(LastChanceHandler);
Then the method:
void LastChanceHandler(object sender, UnhandledExceptionEventArgs args)
{
Exception ex = ((Exception)(args.ExceptionObject));
Logging.WriteLine("****** LastChanceHandler ******");
Logging.WriteLine("ExceptionType: {0}", ex.GetType().Name);
Logging.WriteLine("HelpLine: {0}", ex.HelpLink);
Logging.WriteLine("Message: {0}", ex.Message);
Logging.WriteLine("Source: {0}", ex.Source);
Logging.WriteLine("StackTrace: {0}", ex.StackTrace);
Logging.WriteLine("TargetSite: {0}", ex.TargetSite);
string indent = "" + Microsoft.VisualBasic.Chr(9) + "";
Exception ie = ex;
while (!((ie.InnerException == null))) {
ie = ie.InnerException;
Logging.WriteLine(indent + "****** Inner Exception ******");
Logging.WriteLine(indent + "ExceptionType: {0}", ie.GetType().Name);
Logging.WriteLine(indent + "HelpLine: {0}", ie.HelpLink);
Logging.WriteLine(indent + "Message: {0}", ie.Message);
Logging.WriteLine(indent + "Source: {0}", ie.Source);
Logging.WriteLine(indent + "StackTrace: {0}", ie.StackTrace);
Logging.WriteLine(indent + "TargetSite: {0}", ie.TargetSite);
indent += "" + Microsoft.VisualBasic.Chr(9) + "";
}
}
Any ideas on how to capture what is wrong???
Thanks,
Matt
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote in message news:OC**************@TK2MSFTNGP10.phx.gbl...
HI,
异常说?
尝试使用AppDomain.UnHandledException和/或AppDomain.ThreadException
欢呼,
-
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
佛罗里达州交通局
马特 < MD ***** @ sorvive.DONT-SEND-SPAM.com>在消息中写道
新闻:Oz ************** @ TK2MSFTNGP09.phx.gbl ...
What does the exception says?
Try to use AppDomain.UnHandledException and/or AppDomain.ThreadException
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Matt" <md*****@sorvive.DONT-SEND-SPAM.com> wrote in message
news:Oz**************@TK2MSFTNGP09.phx.gbl...
我编写了一个运行为的控制台应用程序Windows上的批处理作业
2000 Server。每隔一段时间我就会向
控制台抛出异常。有没有办法可以创建一个全局处理程序,可以捕获此异常并阻止应用程序锁定?我在所有数据库和文件写入调用中执行尝试
catch语句,所以我不确定它来自哪里。
非常感谢任何建议或建议。
谢谢,
Matt
I have written a console application that runs as a batch job on Windows
2000 Server. Every once in a while I am getting an exception thrown to the
console. Is there a way I can create a global handler that can catch this
exception and prevent the application from locking up? I am performing try
catch statements at all database and file write calls so I am unsure where
it is coming from.
Any suggestions or recommendations are greatly appreciated.
Thanks,
Matt
这篇关于全局异常处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文