Resuming Try

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I have several statements in my try block. After catching an exception and
dealing with it in catch section, is there a way to resume from next
statement in try section kinda like resume next in vb?

Thanks

Regards
 
John said:
Hi

I have several statements in my try block. After catching an
exception and dealing with it in catch section, is there a way to
resume from next statement in try section kinda like resume next in
vb?

No. You'd have to put each single statement in a try-catch block - or
still use on error resume next.


Armin
 
Hi

I have several statements in my try block. After catching an exception and
dealing with it in catch section, is there a way to resume from next
statement in try section kinda like resume next in vb?

Thanks

Regards

John,
You can use seperate try-catch exception handlers for each statements
alternatively.

Onur
 
John,
Yes, use a Goto statement.

Try
TryAgain1:
Something()
TryAgain2:
SomethingElse()
Catch
If whatever Then
Goto TryAgain1
Else
Goto TryAgain2
End If
End Try

Of course some people feel Goto is evil & should be avoided at all costs; I
view the above more of a "Resume Try" rather then a Goto statement. There
are three simple rules for Goto in a Catch block.

- A Goto can only branch from a Catch statement into the Try block of the
same statement
- A Goto can never branch out of a Finally statement
- A Goto can never branch into a Catch or Finally statement
 
John said:
Hi

I have several statements in my try block. After catching an exception and
dealing with it in catch section, is there a way to resume from next
statement in try section kinda like resume next in vb?

If you want Resume Next then either use the solution Jay showed of using
GoTo from inside the Catch, or you can in fact use On Error Resume Next as
per Visual Basic 6 style of coding and the compiler does that GoTo and
labels for you, but you cannot mix and match that. Personally, I'd do
neither, instead I'd look at refactorign the code out that can cause errors
that you wish to still resume next from, and change that into logical
checking, such as checking for a condition, or a null returned from a method
etc, and also consider multiple small Try Catch blocks.
 
Back
Top