
Originally Posted by
jmcilhinney
Any exceptions that you haven't anticipated leave your app in an unknown state and, therefore, the only genuinely safe course of action is to exit. You should have a global exception handler in all your apps, which means handling the UnhandledException event of the application in VB WinForms, and there you should log the exception and exit. If the client really wants to be able to keep working then you can give them that option but you should make it crystal clear to them that they do so at their own risk.
Here's how we manage unhandled exceptions in one particular app:
vb.net Code:
Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs) Handles Me.UnhandledException
Using dialogue As New frmUnhandledException(e.Exception) With {.StartPosition = FormStartPosition.CenterParent}
Select Case dialogue.ShowDialog()
Case DialogResult.Retry
'Restart
e.ExitApplication = False
Windows.Forms.Application.Restart()
Case DialogResult.Abort
'Exit
e.ExitApplication = True
Case DialogResult.Ignore
'Continue
e.ExitApplication = False
End Select
End Using
End Sub