Continue after error & Application.ThreadException

  • Thread starter Thread starter Matthew Hood
  • Start date Start date
M

Matthew Hood

I have a DLL I created to handle all unknown errors using the
Application.ThreadException event. I'm asking the user if they want to
terminate the program or continue. This is working like I want. The
program exits when I tell it to terminate, and when I continue, the program
keeps running but the routine that generated the error exited. I want to
take this a step further though. Instead of the routine that generated the
error exiting, I would like it to continue with the next line, or even retry
it if possible in some circumstances.

Any ideas on how to accomplish this?

TIA,
-Matt
 
Matthew Hood said:
I have a DLL I created to handle all unknown errors using the
Application.ThreadException event. I'm asking the user if they want to
terminate the program or continue. This is working like I want. The
program exits when I tell it to terminate, and when I continue, the program
keeps running but the routine that generated the error exited. I want to
take this a step further though. Instead of the routine that generated the
error exiting, I would like it to continue with the next line, or even
retry it if possible in some circumstances.

You could use 'On Error Resume Next' inside the method directly. Notice
that this will maybe prevent the 'ThreadException' from being thrown.
 
Matt,
take this a step further though. Instead of the routine that generated
the error exiting, I would like it to continue with the next line, or even
retry it if possible in some circumstances.
Any ideas on how to accomplish this?
Unfortunately there is no "easy" way to do this, as by the time the
Application.ThreadException handler gets the exception the stack is
completely unwound.

The "best" you could do is to put a Try/Catch around each of the commands
you want retry and have the Catch block retry the Try Block. I find using
Goto in the Catch block the "easiest" way to "Retry".

Something like:
Try Retry:

'...something

Catch ex as FileNotFoundException

If MessageBox.Show("File does not exit!", _
Application.ProductName, _
MessageBoxButtons.RetryCancel, _
MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button2) _
= DialogResult.Retry Then
GoTo retry
End If


Instead of the Goto, others have put the entire Try/Catch in a loop...

Hope this helps
Jay
 
Thanks for the responses. The On Error is a no-go. I already got Try/Catch
statements around areas I know COULD cause a problem though I didn't think
about using a goto to try again. Not sure how this could be used in my
applicatoin.Threadexception handler though.

Thanks again.
-Matt
 
Matthew,

When you see my answer above yours to Martin Ho (when the messages are
sorted on sent date) than you can see a sample of my using it in a loop and
a try and catch block.

Cor
 
Matthew,
As I attempted to stated, "goto to try again" cannot be used with
Application.ThreadException.

When you get to the Application.ThreadException handler where you were is
long gone.

Hope this helps
Jay
 

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