Returning from a catch statement

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All

In VB6 I used to catch exceptions in a goto errtrap call then resume if I
could handle the problem and continue within the routine or function

I am not sure how to do this in VB 2005 from within a catch statement

Any ideas appreciated
 
You can´t do that in VB.NET, at least not directly, you have to use nested
Try/Catch blocks

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
 
Steve said:
In VB6 I used to catch exceptions in a goto errtrap call then resume if I
could handle the problem and continue within the routine or function

I am not sure how to do this in VB 2005 from within a catch statement

You cannot exactly do the same without putting each statement into its
separate 'Try...Catch' block. Note that 'On Error GoTo...' is still
available in VB.NET.
 
Steve,
As Carlos suggests, you cannot do that.

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", others have put the
entire Try/Catch in a loop...

BTW: I've heard all the arguments about how Goto is evil & should be
avoided, in this case the "Goto Retry" is more like a "Retry" statement. Yes
"goto retry" could be used for evil, however it can also be used for good...

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


Caution: With either the Goto Retry or a loop, be certain to allow your
users an Out, so you don't get into an endless loop.

Hope this helps
Jay


--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Hi All
|
| In VB6 I used to catch exceptions in a goto errtrap call then resume if I
| could handle the problem and continue within the routine or function
|
| I am not sure how to do this in VB 2005 from within a catch statement
|
| Any ideas appreciated
|
|
| --
| Regards
| Steve
 
Back
Top