Exception with thread

  • Thread starter Thread starter bie2
  • Start date Start date
B

bie2

Hi,

I have this:
- a form
- a user control in the form

In the user control I have a worker thread.
In this worker thread I can throw an exception. I get it back in the UI
thread with a BeginInvoke.

But I want to throw back this exception to the parent form.

Is there another possibility other by an event?

Thanks
 
I used events when I had to do this... As you know exceptions are per thread
- you need to marshal the exception into the GUI thread and rethrow {or
otherwise handle it} and the ".NET way" to do that is via BeginInvoke() or an
event...
 
I'M trying to use an event, but here is the problem.

In the user control I'm doing an EndInvoke to see if something went
wrong like this:
private void ThreadFinished(IAsyncResult ar)
{
try
{
DelegateLoadData loaddata = (DelegateLoadData)ar.AsyncState;
loaddata.EndInvoke(ar);
}
catch( ExceptionSorrento oEx )
{
decimal errorID = ErrorLogClass.ErrorLog(oEx, "User control
Yields", this.GetType().Assembly.ToString(), oEx.IDFErrorLog,
oEx.IDFPlant);
ExceptionCustom oExcept = new ExceptionSorrento( oEx.Message, -1,
errorID );
this.OnException(this, oExcept);
}
catch( Exception oException )
{
decimal errorID = ErrorLogClass.ErrorLog(oException, "User control
Yields", this.GetType().Assembly.ToString());
string strMessage = "An unknown error occurred in the yield user
control.";
ExceptionCustom oExcept = new ExceptionCustom( strMessage, -1,
errorID );
this.OnException(this, oExcept);
}
}

Since the error is not thrown, the stacktrace, method are empty. Is
there a way to have them fill?
 
bie2 said:
Since the error is not thrown, the stacktrace, method are empty. Is
there a way to have them fill?

Why not just propagate the original exception instead of creating a new
one? Or, if you must create a new exception then at least use the
original as the inner exception to the new one.

Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top