Error handling not kicking-in when running exe

A

Al Williams

Hi,

I have error handling in place throughout my application. I also start the
application wrapped in error handling code to catch any unexpected
exceptions (i.e. exceptions that occur where I haven't placed error handling
code).

When I run my app from the IDE, the unhandled errors are caught by the error
handling code in my Sub Main routine and the error details are logged to a
text file and optionally e-mailed to me for follow-up.

However, when I run the app as an EXE (i.e. running the executable - not
from the IDE) - this error handling does not kick-in. Instead, I the default
..NET error message box is displayed (and the error is not logged).

Any idea why this would be happening? Note, I've noticed the same behaviour
when compiling in both "Release" and "Debug" mode.

Here is the part of my Sub Main that traps all other unexpected errors in
the application:


If gblnAuthenticated Then

Try
Application.Run(New frmMain)
Catch ex As Exception
Dim errInfo As String
errInfo = "Source: " + ex.Source.ToString + vbCrLf
errInfo += vbCrLf
errInfo += "Message: " + ex.Message.ToString + vbCrLf
errInfo += vbCrLf
errInfo += "Target: " + ex.TargetSite.ToString + vbCrLf
errInfo += vbCrLf
errInfo += "Stack Trace: " + vbCrLf
errInfo += ex.StackTrace.ToString + vbCrLf
'show form advising user that an unexpected error has occured
Dim frmErr As New frmError
frmErr.ShowDialog()

Try
'call function to log and E-Mail error details to LDS
clsGeneral.fnLogError(errInfo, gblnAutoSendErrorReports)
Catch e As Exception
'if an error occurs while logging the error - just ignore it
End Try
Finally
Application.Exit()
End Try

End If
 
A

Al Williams

No, frmMain does not have any error handling. Basically frmMain has a menu
and toolbar and doesn't do all that much.

However, I have extensive error handling in many of the child forms - but
not ALL the code is encased in "Try..Catch .. End Try" statements.

For these types of unexpected errors, I want the error to "bubble" back up
to SubMain so that the error can be logged and the app shut-down. Like I
said, when running my app from the IDE, this works as expected. But when
running the EXE, I get the default .NET error dialog - which I don't want.

It's probably some obscure setting I haven't configured correctly ...
 
A

Al Williams

Thanks for the info. Any idea why my existing error handling code works one
way when running from the IDE and differently when running from an EXE?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top