Application.ThreadException not getting called

Posted on 2005-04-11
Last Modified: 2008-02-07
I am using .NET 2.0 SDK Beta and trying to trap thread exceptions in order to handle 'unhandled' exceptions and log them. I am running the following line in my Main method:

Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);

The method simply does a MessageBox.Show in order to indicate that it was called. However, it never does get called, instead throwing whatever exception is throw (I have hardcoded one to be thrown). Am I doing something wrong? Additional step, perhaps?

Question by:athomas4219
    LVL 10

    Accepted Solution

    This will not catch exceptions that are thrown from the application's main thread.  To do this, you must wrap your Application.Run statement in a try...catch block.

    Author Comment

    What exceptions will that catch? Exceptions thrown by any OTHER threads?

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now