Quote Originally Posted by jmcilhinney View Post
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:
  1. Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs) Handles Me.UnhandledException
  2.     Using dialogue As New frmUnhandledException(e.Exception) With {.StartPosition = FormStartPosition.CenterParent}
  3.         Select Case dialogue.ShowDialog()
  4.             Case DialogResult.Retry
  5.                 'Restart
  6.                 e.ExitApplication = False
  7.                 Windows.Forms.Application.Restart()
  8.             Case DialogResult.Abort
  9.                 'Exit
  10.                 e.ExitApplication = True
  11.             Case DialogResult.Ignore
  12.                 'Continue
  13.                 e.ExitApplication = False
  14.         End Select
  15.     End Using
  16. End Sub
Name:  DAR Unhandled Exception.PNG
Views: 229
Size:  13.2 KB