开发者

Unhandled exception is not being caught by the handlers

We have registered for the unhandled exceptions in the following way. The application is a remoting server. If an unhandled exception is thrown from the remoting s开发者_开发问答erver it is not handled by the unhandled exception handlers. What could be the problem?

[STAThread]

[Obfuscation(Exclude = true)]
static void Main(string[] args)
{

    Application.ThreadException += new ThreadExceptionEventHandler(OnThreadException);
    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledException);
    .
    .
    .

    Application.EnableVisualStyles();
    Application.Run(form);

}


Hope this method helps you 'Application.SetUnhandledExceptionMode'. It instructs the application how to respond to unhandled exceptions.

static void Main(string[] args)
{

    Application.ThreadException += new ThreadExceptionEventHandler(OnThreadException);
    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledException);

    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

    Application.EnableVisualStyles();
    Application.Run(form);

}


If it's a remoting server and the exception is happening as part of client interaction, then the exception will be sent to the client without causing the server to crash.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜