On Error Resume Next
Unhandled Error Capture
As I mentioned earlier, it's a good idea to include a global error handler in your code, in case some error gets past your defenses. To include this code, display all files in the Solution Explorer using the "Show All Files" button, open the ApplicationEvents.vb file, and add the following code to the MyApplication class.
Insert Chapter 9, Snippet Item 4.
Private Sub MyApplication_UnhandledException( _ ByVal sender As Object, ByVal e As Microsoft. _ VisualBasic.ApplicationServices. _ UnhandledExceptionEventArgs) Handles _ Me.UnhandledException ' ----- Record the error, and keep running. e.ExitApplication = False GeneralError("Unhandled Exception", e.Exception) End Sub
Because we already have the global GeneralError routine to log our errors, we might as well take advantage of it here.
That's it for errors. In the next chapter, which covers database interactions, we'll make frequent use of this error-handling code.