Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6824905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:57:26+00:00 2026-05-26T21:57:26+00:00

How can I get generic occurred errors in windows application or windows services like

  • 0

How can I get generic occurred errors in windows application or windows services like Application_Error in HttpApplication

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:57:27+00:00Added an answer on May 26, 2026 at 9:57 pm

    You can use the following events to trap exceptions in Windows Forms applications and .Net Services:

    AppDomain.FirstChanceException

    This event is triggered whenever there is an exception in a given AppDomain, even if the event is later handled. This is almost certainly not what you want but I thought I’d include it for completeness.

    Note that this is a per-AppDomain event – if you use multiple AppDomains then you need to handle this event for each one. If you only have a single AppDomain (more likely) then the following will handle this event:

    AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;
    
    static void CurrentDomain_FirstChanceException(object sender, FirstChanceExceptionEventArgs e)
    {
        throw new NotImplementedException();
    }
    

    AppDomain.UnhandledException

    This event is triggered whenever there is an unhandled exception in a given AppDomain. Again this is a per-AppDomain event and is wired up in a similar way to the FirstChanceException event.

    AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
    
    static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
    {
        throw new NotImplementedException();
    }
    

    You can hook these two events at any point you like however you probably want to do this as soon as possible otherwise exceptions might be thrown before you hook up your event handler. The start of the Main method in your Program class is normally a good place to do this.

    Note that in a Windows Forms application this event might not get triggered when you would otherwise expect it to as unhandled exceptions in Windows Forms applications are handled differently (by the Windows Forms infrastructure) and so are sometimes not propogated up as unhandled exceptions in the AppDomain.

    Take a look at Why is my Catch block only running while Debugging in Visual Studio?

    Application.ThreadException

    (only for Windows Forms applications)

    This occurs when an unhandled exception is thrown in a Windows Forms application which is then caught by the Windows Forms infrastructure. You should probably be using this instead of AppDomain.UnhandledException to catch unhandled excpetions in Windows Forms applications:

    Application.ThreadException += Application_ThreadException;
    
    static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
    {
        throw new NotImplementedException();
    }
    

    Again you want to hook this up as soon as possible – the start of your Main method in the Program class is normally a good place to do this.

    Summary

    Note that none of them are exactly like the Application_Error method of an ASP.Net application however if you are creating a Windows Forms application then you probably want to use Application.ThreadException and if you are creating a Windows Service then you probably want AppDomain.UnhandledException

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How i can get full right name of generic type? For example: This code
Is there a generic API call I can make to get a handle of
I can get the element like this $(#txtEmail) but I'm not sure how to
I'm trying to get a generic method working in VB.NET but I can't get
Is there a generic way I can get a post-build event to copy the
How can i get index of generic list from form page? For example; aspx.cs
Can get all triples with value null in specific field? All people with date_of_birth
I can get easily see what projects and dlls a single project references from
I can get both System.Net.Mail and System.Web.Mail to work with GMail, but I can't
Logging can get complicated, quickly. Considering that you have some code, how do you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.