Something is inaccurate in what you are seeing or reporting. In v1.0 and
v1.1 of the runtime an unhandled exception will only cause the app to exit
if it occurs on the main thread or a thread that originates in unmanaged
code. Unhandled exceptions on manually created threads, threadpool threads,
etc., will not cause the runtime to exit. The only exception to this is if
the exception thrown is unrecoverable, such as ExecutionEngineException,
StackOverflowException, or OutOfMemoryException.
It is posible that the DLL that you are calling into is itself using
additional threads that are throwing exceptions. If that is the situation
then the try-catch handler you wrap the call to nDLL.DoSomething() in will
not catch the exception.
I'd take Dimitry's advice and add a handler to the
AppDomain.UnhandledException event as well as the
Application.ThreadException event. You wont be able to correct the problem
from there but you should be able to get more information from it.
If you keep having problems you will need to provde more precise information
on what is reported on the exception.
"David" <go********@hotmail.com> wrote in message
news:81**************************@posting.google.c om...
I am having a bit of a problem with catching an exception within a thread.
Here is the scenario:
I have a Windows Form.
I create a new thread.
This new thread calls a method in another DLL that catches an expected
exception. The method in the DLL throws the exception back out.
When in debug mode, the process just exits.
Here is some sample code:
public class myform : system.windows.form {
try {
ThreadClass cl = new ThreadClass();
Thread nThread = new Thread(new ThreadStart(cl.runprocess));
nThread.IsBackground = true;
nThread.Start();
}
catch(Exception ex) {
...
//Exception from thread is never caught
...
}
}
public class ThreadClass() {
public ThreadClass() {}
public void runprocess() {
try {
newDLL nDLL = new newDLL();
nDLL.DoSomething(); //<--- Exception occurrs and is rethrown in
// this method.
...
//Do more stuff //<-- never makes it to here
...
}
catch(Exception ex) {
//Do stuff here //<-- never makess it to here
}
}
}
The thread state after the exception occurrs is always
ThreadState.Running.
What am I misssing?
-David