By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,042 Members | 1,277 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,042 IT Pros & Developers. It's quick & easy.

Exiting a Try block

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"John Dann" <ne**@prodata.co.uk> schrieb:
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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #2

P: n/a
"John Dann" <ne**@prodata.co.uk> schrieb:
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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #3

P: n/a
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


"John Dann" <ne**@prodata.co.uk> wrote in message
news:j5********************************@4ax.com...
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

Nov 21 '05 #4

P: n/a
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


"John Dann" <ne**@prodata.co.uk> wrote in message
news:j5********************************@4ax.com...
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

Nov 21 '05 #5

P: n/a
ACK

U have to construct your code appropriately really

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:ef**************@TK2MSFTNGP11.phx.gbl...
"John Dann" <ne**@prodata.co.uk> schrieb:
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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #6

P: n/a
ACK

U have to construct your code appropriately really

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:ef**************@TK2MSFTNGP11.phx.gbl...
"John Dann" <ne**@prodata.co.uk> schrieb:
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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.