Maanu
Maanu

Reputation: 5203

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 server 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);

}

Upvotes: 2

Views: 3114

Answers (2)

TheCodeKing
TheCodeKing

Reputation: 19230

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.

Upvotes: 0

CharithJ
CharithJ

Reputation: 47560

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);

}

Upvotes: 3

Related Questions