简体   繁体   中英

Debugging an exception that only happens to exe but not from IDE

on closing the main form of the application(which I call so many methods on it,etc) if I run my application from IDE and want to close it, it is ok but if I just run the exe file It will throw an exception.

so what way do you propose to me for debugging it? as I said when I run it from the IDE, it is Ok and no error occurs

Two things I can think of to try:

  • Run the application from outside the IDE but then attach to the process. It could be that when starting from the debugger the environment will be different in some way
  • Use adplus (see my earlier post here to catch the crash dump so you can analyse it later

Find out what the exception is, to start with. Can you already see the exception details? Does it offer you the option of attaching to the debugger? Can you catch the exception and log it?

Attach the debugger after you got the program started. This ensures any side-effects, like the startup directory, the hosting process and JIT optimization cannot be affected by the debugger.

Start your program. Tools + Attach to Process.

I have a solution written in C++-CLI which should be easy enough to port to C#.

If it's happening within the main function itself, have you tried wrapping all your code in a:

try
{
    main();
}
catch( System.Exception^ e)
{
    // do something
}

Apologies for the C++-ish-ness of my answer - it's been a long time since I wrote any C# ;-)

You should be able to attach a global exception handler:

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

And then create a function to handle the exception:

private void Application_ThreadException(object sender,System.Thread.ThreadExceptionEventArgs e) {
    // Do whatever here
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM