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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:19:29+00:00 2026-05-31T07:19:29+00:00

I have an application written in C# / .NET 4 / VS C# Express.

  • 0

I have an application written in C# / .NET 4 / VS C# Express. During debug session (it didn’t happen with release build, but I can’t say for sure, that it won’t in future) my application exits, without any exception info. The only piece in my code, that closes main form, is accesible only with menu File/Exit and it’s Clicked event handler. So it has to be some … ‘exceptional code’. How can I determine, which piece of code killed my app?


Solution if someone would like to use it:

AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler( currentDomain_UnhandledException );

Event handler with file logging

void currentDomain_UnhandledException( object sender, UnhandledExceptionEventArgs e ) {
    using ( FileStream file = new FileStream( Application.StartupPath + "\\errorlog.txt",
        FileMode.Append, FileAccess.Write ) ) {
        StreamWriter streamWriter = new StreamWriter( file );
        streamWriter.WriteLine( "-------------------------------------------------" );
        streamWriter.WriteLine( "---------- " + System.DateTime.Now + " ---------" );
        streamWriter.WriteLine( "-------------------------------------------------" );
        streamWriter.WriteLine( "Terminating: " + e.IsTerminating );
        Exception ex = (Exception)e.ExceptionObject;
        while ( ex != null ) {
            streamWriter.WriteLine( "--------- Exception: ---------- " );
            streamWriter.WriteLine( ex.GetType() );
            streamWriter.WriteLine( ex.Message );
            streamWriter.WriteLine( ex.HelpLink );
            streamWriter.WriteLine( ex.Source );
            streamWriter.WriteLine( ex.StackTrace );
            ex = ex.InnerException;
        }
        streamWriter.WriteLine();
        streamWriter.Close();
        MessageBox.Show( ( (Exception)e.ExceptionObject ).Message );
    }
}
  • 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-31T07:19:31+00:00Added an answer on May 31, 2026 at 7:19 am

    First of all, you should have exception handling around all your code.

    If it’s still occurring you can attach an event handler to the AppDomain.UnhandledException event

    Note that your application is still going to crash, but this at least gives you the ability to log the exception.

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

Sidebar

Related Questions

We have a ASP.NET web application written in VB.NET where we build content programmatically
I have a Windows application written in C#/.NET. How can I play a specific
I have an application written in C#.Net (Framework 2.0 if it matters). It calls
I have an application written in VB.NET that interacts with Excel via interop. I
We have an application written in both C++ and .NET that installs for all
We have an application written in C#, using .NET Framework 3.0 or 3.5 or
I have a .net MDI application written in vb.net. I'm trying to program a
I have a WinForms application written in C# for .NET 3.5 that needs to
I have a simple application written in C# and .Net 2.0 that displays several
I have this code in my ASP.NET application written in C# that is trying

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.