473,396 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Continue after error & Application.ThreadException

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
5 3908
"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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: VM | last post by:
Is it possible to intercept all exception errors into one Try...Catch? I've tried wrapping Application.Run() in a Try...Catch, but it doesn't seem to work all the time. Thanks.
5
by: Jason MacKenzie | last post by:
I have a production critical windows forms application. I have try catch blocks everywhere to handle every eventuality. However occasionally, every couple of months, the application crashes. Its...
2
by: Lucas Tam | last post by:
Without writing try/catch statements is there a way to have a global error handler in VB.NET? In ASP.NET there is an application level error handler inside Global.asax, but is there something...
4
by: Paul Wilson | last post by:
I want to use Err.Raise() method to raise my own exceptions. Is this the right way of raising my own exceptions ? (i think this is the only way). What is the Error number i can safely use,...
8
by: jcrouse | last post by:
I am using the following code to trap errors in a sub routine: Try Executable code Catch ex As Exception Dim strInputE As String = Application.StartupPath & "\Error.txt" Dim srE As...
4
by: sm | last post by:
Hi, I have a couple of questions with regards to handling errors and exceptions. 1. If I use On Error goto Errhandler ... Errhandler:
1
by: Mesan | last post by:
Has anyone else noticed that even though you handle an exception that happens within the background worker that the UnhandledException event still fires? For example, here's my ThreadException...
5
by: =?Utf-8?B?c3VydHVyeg==?= | last post by:
Hi, I feel like a noob for asking this. When I publish a VB windows application, I want to disable the ability of the the user to continue when there is an unhandled exception. For example,...
0
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, My C# application trys to access directorycontext during Form loading. Try and Catch if there is an exception. I then output an error message and then "this.Close();" to exit the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.