By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 959 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

Continue after error & Application.ThreadException

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Matthew Hood" <Dr***********@Yahoo.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2

P: n/a
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

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

Hope this helps
Jay

"Matthew Hood" <Dr***********@Yahoo.com> wrote in message
news:Of*************@TK2MSFTNGP09.phx.gbl...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

Nov 21 '05 #3

P: n/a
Jay,

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

Exactly saves me to write it?

Thanks

:-)

Cor
Nov 21 '05 #4

P: n/a
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 Hood" <Dr***********@Yahoo.com> wrote in message
news:Of*************@TK2MSFTNGP09.phx.gbl...
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

Nov 21 '05 #5

P: n/a
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
Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.