Home > other >  My Application crashes if there is an unhandled exception in my Class Library?
My Application crashes if there is an unhandled exception in my Class Library?

Time:03-11

What I am doing is basicly creating a .DLL. I have a lots of stuff going inside these DLL-s, and it happens that I miss a scenario and something unexpected happens. I am working on it on unit tests, but I want to be hundred percent sure, that my WinForms app will never crash.

What I have:

One Solution with two projects:

  • ProjectDLL (Class Library)
  • ProjectWinForms (Windows Forms Application [.NET Framework])

What I did:

In ProjectWinForms I added this to ApplicationEvents.vb

  Private Sub MyApplication_UnhandledException(sender As Object, e As UnhandledExceptionEventArgs) Handles Me.UnhandledException
        Bugsplat_Lander.ExeptionToShow = e.Exception
        Bugsplat_Lander.Show()
        Bugsplat_Lander.BringToFront()
        e.ExitApplication = False
    End Sub

This works fine as long as the exception occurs in my ProjectWinForms project. However, if I build a Release version, move it to another computer, and create an exception; my application will simply close, and write the error in Windows Events.

What I want to achive:

Basicly the nicest thing would be to open up this form even if the exception happens in my ProjectDLL code, without quiting the application.

I am a sure that I am the one doing something wrong, I just can't figure out what.

CodePudding user response:

At first the golden rule is: If your code creates an exception, it has to be handled otherwise your application runs in a dirty state. For your problem take a look to Application.SetUnhandledExceptionMode Method. Maybe this could help you

  • Related