I've been a vb.net coder for many years now, though only for personal or work related tasks. I'm currently developing an application for my company, that will be among the first projects I've done for public use. As such, I've been much more conscious of the effects that an unhandled error could cause.
It was with this in mind, that I came across one of those little tips that seems so obvious, I feel like should have known it all along. It turns out that there's no excuse at all for an unhandled error ever stopping your application. Global error handling is part of the .net design, and implementing it is as easy as this:
Imports System.Threading
..
Public Sub HandleGlobalErrors()
AddHandler Application.ThreadException, AddressOf Application_ThreadException
End Sub
Private Sub Application_ThreadException(ByVal sender As System.Object, _
ByVal e As ThreadExceptionEventArgs)
'add your global error handling here
End Sub
once you call the handleglobalerrors sub, all uncaught exceptions will be directed to the Application_ThreadException sub. Simple.
Monday, January 4, 2010
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment