By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,199 Members | 1,725 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,199 IT Pros & Developers. It's quick & easy.

Global error catching...

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.
**************************************
"Stu" <st****@ntpcl.uk.com> wrote in message
news:#R*************@TK2MSFTNGP10.phx.gbl...
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

Nov 19 '05 #2

P: n/a
"Stu" <st****@ntpcl.uk.com> wrote in message
news:%2*******************@TK2MSFTNGP10.phx.gbl...
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....ml/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

Nov 19 '05 #3

P: n/a
Hello,

"Stu" <st****@ntpcl.uk.com> schrieb:
Is there any way to catch every exception raised in an
application (in order to write it to a log file for example).


Even handled exceptions?!

For Windows Forms (ThreadException, ...):

http://msdn.microsoft.com/library/en...ptiontopic.asp

Regards,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.