I'm guessing from your description that this is a WinForms application.
When you run a WinForms application under control of the Visual Studio
debugger (regardless of whether it's compiled for release or debug
mode), execution flow is exactly the way the code reads: just what you
would expect.
However, when you run it directly under Windows, execution flow
changes. Someone explained the precise details to me once but my memory
is a bit foggy on details. I'll give the best explanation I can,
though.
If you invoke a dialog, something like this:
DialogResult result = myDialog.ShowDialog();
you would think that you could catch any exceptions raised by the
dialog like this:
try
{
DialogResult result = myDialog.ShowDialog();
...
}
catch (Exception e)
{
...
}
and any exception raised by the dialog would be caught in the "catch"
block. In Visual Studio, this is exactly what happens.
However, when you run directly under Windows, the system doesn't really
call your dialog and then just sit there inside the try block waiting
for it to return. Somehow (I'm not sure how), control returns to the
underlying windowing system, which shows the dialog. Control is often
returned to the underlying system at strategic points in your
application. That's why when that dialog throws an exception, the
exception bubbles up not to your calling code, but right back to the
windowing system and the CLR, where it is treated like an unhandled
exception.
As I said, my memory of this isn't perfect, and my example may not be
exactly right, but that's basically what's going on in WinForms.
The only way to catch these exceptions and log them is by handling the
AppDomain.UnhandledException
and
Application.ThreadException
events.
Robin Riley wrote:
Hi,
I have a .NET solution that contains a dll project and a tester application
project which, of course, invokes the dll. The dll project has exception
handling in it. What's happening is that when I run the executable from
within the .NET studio environment, thrown exceptions are caught and handled
correctly (both debug and release mode). However, if I run the executable
from outside the .NET studio, none of the exceptions get caught. In fact,
what I get is a pop-up telling me an unhandled exception has occurred and
pointing me right back to where the (valid) exception was thrown from. I
thought perhaps it was something I was doing wrong in my solution so I
created a little bare-bones dll and test app but the same thing still happens.
Has anyone ever seen anything like this? Any ideas as to what the problem
might be would be greatly appreciated! Btw, I had another much more
experienced co-worker look at this as well and he couldn't figure it out
either.
Regards,
Robin