Re: Multiple Catches in Try/Catch
- From: "Larry Lard" <larrylard@xxxxxxxxxxx>
- Date: 16 Jan 2006 09:26:57 -0800
zacks@xxxxxxxxxxxxxxxxxxxxxxxx wrote:
> The help isn't clear on this. If I have multiple catches and the first
> one catches the particular exception that was thrown, does it check the
> rest of the catches in the try/catch?
from the docs (emphasis added):
If an exception occurs, Visual Basic examines the Catch statements in
the order they appear within Try...Catch...Finally. If it finds a Catch
statement that handles the generated exception, it executes ***the
corresponding statement block. When it has finished executing the Catch
block, it executes the Finally block if it is present. Execution then
proceeds to the statement following the End Try statement.***
>
> For example, I want to execute a SQL command and if it times out I want
> to warn the user and continue. If any other error occurs I want to
> treat it as a "fatal" error,
>
> Try
> cmd = New SqlCommand("some sql code", connection)
> cmd.CommandTimeout = 120
> cmd.ExecuteNonQuery
> Catch ex as TimeoutException
> <warn the user that a timeout occured>
' now execution jumps to a Finally block (if present) or to just after
End Try (if not)
> Catch ex as Exception
> <log fatal error>
> Exit Function
> End Try
>
> Or do I really need a Exit Try in the TimeoutException's Catch?
No.
--
Larry Lard
Replies to group please
.
- References:
- Multiple Catches in Try/Catch
- From: zacks
- Multiple Catches in Try/Catch
- Prev by Date: Multiple Catches in Try/Catch
- Next by Date: Click in VB the Combobox
- Previous by thread: Multiple Catches in Try/Catch
- Next by thread: Re: Multiple Catches in Try/Catch
- Index(es):
Relevant Pages
|