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 7804495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:56:02+00:00 2026-06-02T01:56:02+00:00

I am new to C#. I am writing a small desktop form based application

  • 0

I am new to C#. I am writing a small desktop form based application and I need to have this feature in the app.

If the application crashes at any time, there should be a last opportunity for the app to collect stack trace and send it back to me…

Please give me directions on this.

Do I need a try catch covering the main the entry point of my app ?? or what is the best way to handle such things in a C# app.

thank you,

  • 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-06-02T01:56:04+00:00Added an answer on June 2, 2026 at 1:56 am

    To catch all unhandled exceptions, Add this to program.cs:

        [STAThread]
        static void Main()
        {
        AppDomain currentDomain = default(AppDomain);
        currentDomain = AppDomain.CurrentDomain;
        // Handler for unhandled exceptions.
        currentDomain.UnhandledException += GlobalUnhandledExceptionHandler;
        // Handler for exceptions in threads behind forms.
        System.Windows.Forms.Application.ThreadException += GlobalThreadExceptionHandler;
        ...
        }
    
    private static void GlobalUnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e)
    {
       Exception ex = default(Exception);
       ex = (Exception)e.ExceptionObject;
       ILog log = LogManager.GetLogger(typeof(Program));
       log.Error(ex.Message + "\n" + ex.StackTrace);
    }
    
    private static void GlobalThreadExceptionHandler(object sender, System.Threading.ThreadExceptionEventArgs e)
    {
       Exception ex = default(Exception);
       ex = e.Exception;
       ILog log = LogManager.GetLogger(typeof(Program)); //Log4NET
       log.Error(ex.Message + "\n" + ex.StackTrace);
    }
    

    Stack trace you can get by exception.StackTrace

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

Sidebar

Related Questions

I am new to network programming, and have been learning this by writing small
I'm writing a small program that creates a new Windows desktop, switches to it
I'm writing small VB.Net app which should build reports based on data gathered from
I'm writing a small application to teach myself new design and information retrieval tricks.
I'm totally new to Mac OS and iPhone and I'm writing some small app.
I'm currently writing a small test Android app, and have run across a small
I'm currenty writing small application for image processing. However I have a big problem
I'm fairly new to C and have started out writing a small library with
I have been writing a small application using C# to copy a document into
I'm fairly new to C but writing a small multithreaded application. I want to

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.