none
Unhandled exception handler no longer being invoked. RRS feed

  • Question

  • Not sure if this should be here or in the .Net framework forum.

    Visual Studio 2010 and Framework 4.0

    But here goes - This has been working for years but suddenly it doesn't.  I have a unhandled exception handler (code below) that for some reason never its invoked when an exception occurs.  The handler is in the top most part of the app. - the UI.  The original exception occurred 4 levels deep and has worked in the past.  As part of trying to figure out what is going on I threw an exception in the UI and it did not invoke the handler.  What has changed?  Have I accidently changed some setting?

    Here is the code contained in the ApplicationEvents.vb:

    Namespace My
    
        ' The following events are available for MyApplication:
        ' 
        ' Startup: Raised when the application starts, before the startup form is created.
        ' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
        ' UnhandledException: Raised if the application encounters an unhandled exception.
        ' StartupNextInstance: Raised when launching a single-instance application and the application is already active. 
        ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
        Partial Friend Class MyApplication
    
            Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal ex As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException
                Dim msg As String = "A unhandled exception has occured.  Please contact PayBreeze support with the following information."
                msg &= Microsoft.VisualBasic.ControlChars.CrLf
                msg &= ex.Exception.Message
                MsgBox(msg, MsgBoxStyle.OkOnly, "Unhandeled Exception")
                My.Computer.Clipboard.SetText(ex.Exception.ToString & vbCrLf & "Stack Trace:" & vbCrLf & ex.Exception.StackTrace)
                msg = "A stack trace has been put on the clipboard.  Please paste it ([Ctrl]-V) into an email and send to Support@PayBreeze.com"
                msg &= vbCrLf & "Please include other infromation like state, local tax name, Catalog Revision (if not the current one) etc."
                MsgBox(msg, MsgBoxStyle.OkOnly, "")
                End
            End Sub
        End Class
    End Namespace

    Thanks in advance for any help.


    Terry

    Wednesday, October 9, 2019 4:12 PM

All replies

  • Code looks fine. Try removing END and the copy to clipboard.

    Here is what I used years ago when writing desktop apps.

    https://code.msdn.microsoft.com/Dealing-with-unhandled-9b933818/sourcecode?fileId=152864&pathId=1004287432


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, October 9, 2019 5:00 PM
    Moderator
  • Hi Karen and thanks - no change (as I suspected) How can the code in the event be a problem if the event never gets invoked?  

    Terry

    Wednesday, October 9, 2019 5:11 PM
  • Hi Karen and thanks - no change (as I suspected) How can the code in the event be a problem if the event never gets invoked?  

    Terry

    That's what I wanted to know. The only time I've seen something like this is with a uncatchable exception which can be replicated with Environment.FailSafe

    Next thing to try, create a simple project with the same unhandled exception code as in the current project. Place a button on the main form, double click the button and add the following code.

    Dim MyError = CType(sender,ListBox)

    Run the project, did the same thing happen as to the current project or not? If the same thing happened it's an environment issue else something really bad in your code or a corrupt file. When I say bad code it's not necessarily your code but some code in a referenced DLL.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, October 9, 2019 6:36 PM
    Moderator
  • Hi and thanks again Karen.  Works perfectly fine.  And I will swear that it did not work when I threw an exception in the UI, it is now working.  I am going to go layer by layer and see if it is "depth" related.  I first put this app out in 2011 and this has worked since then w/o problems - something has to of changed.

    BTW - is their some way while debugging "like step-into" that can get me past where the exception is Thrown in order to see where it is going?


    Terry

    Wednesday, October 9, 2019 8:17 PM

  • BTW - is their some way while debugging "like step-into" that can get me past where the exception is Thrown in order to see where it is going?


    Terry

    Only way is with a try-catch.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, October 9, 2019 8:59 PM
    Moderator
  • Can you try this. And when doing so try the second button first.

    https://1drv.ms/u/s!AtGAgKKpqdWjjWPYiEud6iu-6p9r?e=k9QW7H



    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Saturday, October 12, 2019 10:28 AM
    Moderator
  • Hi Karen and thanks - no change (as I suspected) How can the code in the event be a problem if the event never gets invoked?  

    Terry

    Maybe no change, but End in a program means the same as kill every step behind it and let all thrash in memory. 

    Success
    Cor

    Saturday, October 12, 2019 2:10 PM