Invisionsoft
Well-known member
Hi there
I'm (trying) to handle all exceptions in my application as it's quite big and many errors can occur. I have this code, but its not doing what I want:
Which Should call HandleSub because a can't be divided by b, right? Becuase it's division by zero.
So when I debug the project from inside VS2008, it shows the Message ( MsgBox("Handler caught : " + ex.Message) ), which is what I want.
But the real problem is when you run the exe like a normal user. The exception isn't handled at all. I get the standard "An error has occured in your application" dialog.
It's puzzling because I get different results. And unlike many people this is not unresearched, I've googled for an hour with different samples of code and this is the best so far but no where near perfect or suitable.
All I really want is for all exceptions to be handled easily without using Try ... Catch in all sub procedures/functions.
Please help me =D
- James
I'm (trying) to handle all exceptions in my application as it's quite big and many errors can occur. I have this code, but its not doing what I want:
VB.NET:
Sub HandleSub(ByVal sender As Object, ByVal args As UnhandledExceptionEventArgs)
Dim ex As Exception = TryCast(args.ExceptionObject, Exception)
MsgBox("Handler caught : " + ex.Message)
mainform.HandleException(ex, args.IsTerminating)
End Sub 'MyUnhandledExceptionEventHandler
Private Sub mainform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim currentDomain As AppDomain = AppDomain.CurrentDomain
AddHandler currentDomain.UnhandledException, AddressOf HandleSub
Dim a, b, c As Integer
a = 3
b = 0
c = a / b
... Rest of start up code
Private Shared Sub HandleException(ByVal ex As Exception, _
ByVal t As Boolean)
'Future code to send info to developer (ME!)
End Sub
Which Should call HandleSub because a can't be divided by b, right? Becuase it's division by zero.
So when I debug the project from inside VS2008, it shows the Message ( MsgBox("Handler caught : " + ex.Message) ), which is what I want.
But the real problem is when you run the exe like a normal user. The exception isn't handled at all. I get the standard "An error has occured in your application" dialog.
It's puzzling because I get different results. And unlike many people this is not unresearched, I've googled for an hour with different samples of code and this is the best so far but no where near perfect or suitable.
All I really want is for all exceptions to be handled easily without using Try ... Catch in all sub procedures/functions.
Please help me =D
- James
Last edited: