Tim8w

I have a case where I need to resume execution on the next line after an exception. Is there no way to do this using the structured error handling I realize that I can go back to the "On Error .. Goto", but I can't believe there's not a way to do this with structured error handling...


Re: Visual Basic General Resolved Sort of: Try Catch - Resume Next?

Peter Ritchie

No, there is no way to do that, you resume at the statement after the catch.




Re: Visual Basic General Resolved Sort of: Try Catch - Resume Next?

Tim8w

I'm beginning to see that I have little choice than to for this one function, to use the old error handling method. On Error Goto - Resume Next. Thank goodness they left this option available or I would have had to have 180 Try...Catch's in this function...




Re: Visual Basic General Resolved Sort of: Try Catch - Resume Next?

James A. Gayhart

Hi,

Though not the ideal way, you could try something like this:

Code Snippet

Private Sub FaultyFunction()

Dim iStep As Integer = 0

Do

Try

Select Case iStep

Case 0

Debug.Print(CStr(1 / 0))

Case 1

AnotherBuggyFunction()

Case Else

Exit Do

End Select

Catch ex As Exception

End Try

iStep += 1

Loop

End Sub






Re: Visual Basic General Resolved Sort of: Try Catch - Resume Next?

Aw Ali

FYI, if there is any line of code you want to execute after an exception is handled by {try, cath}, you may use the finally block of that structure.

Try

'Do something

Catch ex as Exception

'Executes only if there is an error

Finally

'Executes regardless of whether an exception is thrown or not.

End try

That [in the finally block] is where I would put any statement to be executed after an error is handled.






Re: Visual Basic General Resolved Sort of: Try Catch - Resume Next?

James A. Gayhart

Hi,

I believe that the OP has several lines of code that could raise an error but wants to continue to the next line if any line has an error instead of skipping a block of code.