H
Homa
Hi,
I have a problem about thread related exception handling.
I created a background thread to fill a DataTable in a Windows
Application. Inside the code, I have
foreach (…)
{
try
{
da.Fill(dt);
}
catch (ThreadAbortException)
{
// It terminates
return;
}
catch (OleDbException e)
{
// Table not found.
if (e.Message.StartsWith("The Microsoft Jet database
engine cannot find the input table or query"))
break;
else
throw;
}
finally
{
conn.Close(); // Play safe
}
}
The problem is there are three kinds of OleDbException that
could be throw:
-- Table not Found, which I've taken care of (and this
consider normal to the program because it will search through
different tables
-- Connection error: The connection doesn't exist from the
beginning.
-- Network error: The connection was there but got
disconnected.
For the Connection error and Network error, I want the main
thread to trap it, display a message and continue to run.
How do I do it?
I tried Application.ThreadException and
CurrentDomain.UnhandledException but neither works
Best Regards,
Homa
I have a problem about thread related exception handling.
I created a background thread to fill a DataTable in a Windows
Application. Inside the code, I have
foreach (…)
{
try
{
da.Fill(dt);
}
catch (ThreadAbortException)
{
// It terminates
return;
}
catch (OleDbException e)
{
// Table not found.
if (e.Message.StartsWith("The Microsoft Jet database
engine cannot find the input table or query"))
break;
else
throw;
}
finally
{
conn.Close(); // Play safe
}
}
The problem is there are three kinds of OleDbException that
could be throw:
-- Table not Found, which I've taken care of (and this
consider normal to the program because it will search through
different tables
-- Connection error: The connection doesn't exist from the
beginning.
-- Network error: The connection was there but got
disconnected.
For the Connection error and Network error, I want the main
thread to trap it, display a message and continue to run.
How do I do it?
I tried Application.ThreadException and
CurrentDomain.UnhandledException but neither works
Best Regards,
Homa