Unhandled Exceptions

  • Thread starter Andreas van de Sand
  • Start date
A

Andreas van de Sand

Hi everyone,

I've got an application which uses a custom exception handler and to avoid
unhandled exceptions I've got a try{}catch (Exception){} block around the
main Application.Run(...).

Works all good on my machine, whenever something unexpected happens the
exception get caught, logged and it shows a nicer message.
Unfortunately for some reason, this only works on my machine! If i deploy my
project to some other computer I get the .net unhandled exception screen!
how can that be? shouldn't that try/catch catch _everything_?? I'm catching
different types, but the last catch block catches (Exception ex)! How can
anything get around that?

Any suggestions?

Thanks very much.

Cheers
Andreas van de Sand
 
N

Nicholas Paldino [.NET/C# MVP]

Andreas,

Instead of using a try/catch block around the static Run method, why not
attach to the ThreadException event on the Application? It should give you
a consistent way to catch unhandled exceptions on the UI thread.

Hope this helps.
 
A

Andreas van de Sand

Hi Nicholas,

thanks very much, exactly what I needed!
Still don't know why I didn't get all exceptions via try/catch, but I guess
it's a lot better this way anyway...
thanks again, much appreciated.

Cheers
Andreas

Nicholas Paldino said:
Andreas,

Instead of using a try/catch block around the static Run method, why
not attach to the ThreadException event on the Application? It should
give you a consistent way to catch unhandled exceptions on the UI thread.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Andreas van de Sand said:
Hi everyone,

I've got an application which uses a custom exception handler and to
avoid unhandled exceptions I've got a try{}catch (Exception){} block
around the main Application.Run(...).

Works all good on my machine, whenever something unexpected happens the
exception get caught, logged and it shows a nicer message.
Unfortunately for some reason, this only works on my machine! If i deploy
my project to some other computer I get the .net unhandled exception
screen! how can that be? shouldn't that try/catch catch _everything_??
I'm catching different types, but the last catch block catches (Exception
ex)! How can anything get around that?

Any suggestions?

Thanks very much.

Cheers
Andreas van de Sand
 
G

Guest

Just to clear up a "it works on my machine" confusion... Unfortunatly both VS
2003 and VS 2005 do treat exceptions differently in debug modes. If you will
try to run your application without debugging ("Start without debugging"), or
just run .exe, you should get the same unhandled exception screen.
 

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