Global Exception Handling in C#

by Mark Milec 4/7/2008 9:10:00 AM

I've been using the Application_Error event in ASP.NET as a global exception handler for a while.  While looking for a way to implement something similar for Windows Forms I found this post: http://blogs.msdn.com/tom_krueger/archive/2005/02/17/375602.aspx   explaining how to use Application.ThreadException to do just that.

I then found out that Application.ThreadException is not available in the .net Compact Framework but as explained here: http://www.danielmoth.com/Blog/2004/12/appdomainunhandledexception-part-1.html, AppDomain.CurrentDomain.UnhandledException can be used to accomplish the same thing.

There are some problems with using AppDomain.CurrentDomain.UnhandledException as explained here: http://www.codinghorror.com/blog/archives/000201.html

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Related posts

Comments

6/18/2009 12:47:31 PM

Leigh McCulloch

I'm using the .NET Compact Framework 2.0 and we have this function and I can use it to catch exceptions, however there are still some GUI thread exceptions that disappear into the message loop, causing Application.Run to exit, but no exceptions are showing up anywhere.

Any advice? I think it is because I need to implement Application.ThreadException, to handle exceptions that are in the GUI thread, however in the CF2.0 it isn't implemented.

Leigh McCulloch au

6/18/2009 1:01:48 PM

Leigh McCulloch



I’m using the .NET Compact Framework 2.0 and we have this function and I can use it to catch exceptions, however there are still some GUI thread exceptions that disappear into the message loop, causing Application.Run to exit, but no exceptions are showing up anywhere.

Any advice? I think it is because I need to implement Application.ThreadException, to handle exceptions that are in the GUI thread, however in the CF2.0 it isn’t implemented.

Leigh McCulloch au

10/16/2009 5:29:47 AM

personal loans

I guess there's always an easier way ...

personal loans us

10/27/2009 9:09:02 PM

cash loans

Just try to smile for about 2-3 mins then you can get back to work

cash loans us

11/2/2009 9:44:59 AM

cash loans

I guess there's always an easier way ...

cash loans us

11/4/2009 7:41:28 AM

fast payday loans

Interesting ... as always - is your blog making any cash advance ? ;)

fast payday loans us

11/8/2009 4:49:26 AM

payday loans

Yea nice Work !Laughing

payday loans us

11/12/2009 1:13:29 PM

faxless payday loans

Just wanted to say thanks for this.

faxless payday loans us

11/16/2009 3:12:04 AM

payday loans

I just hope to have understood this the way it was meant

payday loans us

11/18/2009 9:17:22 AM

payday loans

Yea nice Work !Laughing

payday loans us

Powered by BlogEngine.NET 1.3.1.0
Theme by Mads Kristensen

About the author

Name of author Mark Milec
Senior Application Developer at Atlas Tube

View Mark Milec's profile on LinkedIn E-mail me Send mail

Calendar

<<  July 2010  >>
MoTuWeThFrSaSu
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar

Pages

    Recent comments

    Archive

    Authors

    Categories

    None


    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2010

    Sign in