Global error catching...

S

Stu

Hi,

Is there any way to catch every exception raised in an application (in order
to write it to a log file for example).

Thanks in advance,

Stu
 
A

ANDRES BECERRA

Here is what I use quite successfully...

1. The very first line of code to run should be:

AddHandler Application.ThreadException, AddressOf
modGlobal.OnThreadException

2. In a standard module called modGlobal, add a method called
OnThreadException that looks like this:

Public Sub OnThreadException(byval sender as object, byval t as
System.Threading.ThreadExceptionEventArgs)

dim exp as Exception = t.exception
dim strMsg as string
strMsg = String.Format("We're sorry, an untrapper error occurred.{0}The
error messaged was:{0}{1}",vbcrlf,exp.ToString)
msgbox(strMsg)
End Sub

--
**************************************
Andrés Becerra
Pennsylvania, USA
Email not posted due to email stealing A**H***S that poll newsgroups.
**************************************
 
J

Jeremy Cowles

Stu said:
Hi,

Is there any way to catch every exception raised in an application (in order
to write it to a log file for example).

MS has released the so-called Application Block for exceptions. You can find
it here:
http://search.microsoft.com/gomsuri...soft.com/library/en-us/dnbda/html/emab-rm.asp

This may be more than your looking for, and by default exceptions "bubble
up", meaning that if you have one Try...Catch block around your entry point
code, it will catch ALL exceptions for the entire application (granted they
are not caught earlier at a deeper level of execution).

Good Luck,
Jeremy
 

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