Re: Multiple Catches in Try/Catch
- From: "AMDRIT" <amdrit@xxxxxxxxxxx>
- Date: Mon, 16 Jan 2006 11:29:10 -0600
No,
the catch will fall until it finds a match, then the catch routine is
completed. The preferred way to catch exceptions is to go from most like
(Specific) to least likely (Unspecific)
try
catch(ex as mycustomexpection)
'We threw this one ourselves, its probably recoverable
catch(ex as TimeoutException)
'We took too long, but probably recoverable
catch(ex as applicationexception)
'Unexpected exception, in the application
'Report, log, and ask to stop
catch(ex as system.exception)
'Unexpected exception, not in the application
'Report, log and stop
finally
'Perform and ultimate clean up here
end try
Hope that helps.
<zacks@xxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:1137431762.315134.49950@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> 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?
>
> 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>
> Catch ex as Exception
> <log fatal error>
> Exit Function
> End Try
>
> Or do I really need a Exit Try in the TimeoutException's Catch?
>
.
- References:
- Multiple Catches in Try/Catch
- From: zacks
- Multiple Catches in Try/Catch
- Prev by Date: Click in VB the Combobox
- Next by Date: Dynamic variable/object name reference. how to do in VB.NET?
- Previous by thread: Re: Multiple Catches in Try/Catch
- Next by thread: Re: Multiple Catches in Try/Catch
- Index(es):
Relevant Pages
|