Question: I catch generally unhandled exceptions with
AddHandler System.AppDomain.CurrentDomain.UnhandledException, AddressOf OnUnhandledException
The problem now is, with this exception handler
Public Sub OnUnhandledException(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs)
Console.WriteLine(e.ExceptionObject.ToString())
Console.WriteLine("Press Enter to continue")
Console.ReadLine()
'Environment.Exit(1)
End Sub
program execution still throws the exception if I don’t exit the program.
Now I want to know how I can change that to a ‘on error resume next’ behaviour ? Is it possible at all ?
<STAThread()> _
Public Sub Main(ByVal argv As String())
'For i As Integer = 0 To argv.Length - 1 Step 1
'Console.WriteLine("Argument {0}: {1}", i, argv(i))
'Next i
AddHandler System.AppDomain.CurrentDomain.UnhandledException, AddressOf OnUnhandledException
Throw New Exception("Test")
Console.WriteLine("Continue")
End sub
If you want to do anything beyond quickly logging or alerting the user of an exception before the program exits, you need to handle the exception normally with a
try/catchblock. Exceptions should be handled as soon as possible to make a real decision about how to react.UnhandledExceptionmay sound like it would be a great place to centralize all your exception handling, but that’s not it’s intended purpose and would get very complicated if it had to handle every exception thrown anywhere in the application.