Exiting a Try block

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

John Dann

I want to use a block of code as follows:

Function..........
' Preliminary processes that acquire a value for X
Try
Select Case X
Case 1 etc

Case 2 etc

Case Else
Exit Function
End Select
Catch
Etc
End Try
End Function

But I'm not completely sure whether exiting the overall function in
the middle of the Try block is legal/robust. Can anyone reassure me
please?

JGD
 
John Dann said:
I want to use a block of code as follows:

Function..........
' Preliminary processes that acquire a value for X
Try
Select Case X
Case 1 etc

Case 2 etc

Case Else
Exit Function
End Select
Catch
Etc
End Try
End Function

But I'm not completely sure whether exiting the overall function in
the middle of the Try block is legal/robust. Can anyone reassure me
please?


Yes, that will work. Nevertheless, notice that a 'Finally' block will be
executed even if you jump outside the block.
 
Do it like this

Try



If True Then

Exit Try

End If

'Never Gets Executed

Catch ex As Exception

Exit Try

'Nor does this

End Try
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top