why can't i catch an Application.ThreadException all the time!?

G

giddy

hi,

I made this little crash reporter system for my project. It works by
getting hooked up to the Application.ThreadException event. If an
unhandled exception occurs , it logs it and then puts it on my ftp
account.

I tested it out and it works perfectly , I test it by Add : "throw new
Exception("Test");"

But if i add this "test" exception into the constructor *of a class
that my main form uses* , i don't end up catching the un-handled
exception!

I also don't end up catching exceptions thrown by my business classes
which are in a seperate Assembly (HotelManager.Core.dll). (The UI
assembly references this assembly)

Why is there such a Uncertainness to this Event?

static void Main()
{
Application.EnableVisualStyles();

Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
ExceptionLogger ex = new ExceptionLogger();
Application.ThreadException += new
ThreadExceptionEventHandler(ex.UnhandledExceptionEventHandler);
Application.Run(new FrmMain());
}

Thanks
Gideon
 
A

Alvin Bruney [MVP]

Not to burst your bubble but you really should try using the enterprise
library instead of rolling your own code. The el contains an exception
handling block that is configuration driven. I'm pretty sure your rolled
code isn't.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
https://www.microsoft.com/MSPress/books/10933.aspx
OWC Black Book www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
 
G

giddy

hi,

I have enterprise lib , buts thats an overkill for me!

Thanks peter , AppDomain.UnhandledException works perfectly. I did try
it in the first place , but the handler was'nt static then!!! , so it
did'nt work.I then found out about thread exception and used it
instead.

I placed "test exceptions" at a number of places , ctors ,
properties , and in external assemblies , they all get caught by the
UnhandledExceptionEvent , and my crash reporter gets them.

There is however a small little quirk. After the crash report is sent
or not , i still get the regular "HotelManager.exe had a problem ,
please report this to microsoft"
Is there a way to prevent that from showing up!?

Thanks so much

Gideon
 

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