开发者

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

开发者 https://www.devze.com 2023-01-06 19:57 出处:网络
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 excep

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 yo开发者_运维技巧u 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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号