Try...Catch question

  • Thread starter Thread starter jy836
  • Start date Start date
J

jy836

When using the Try...Catch...Finally statements, what happens if an error
occurs in a procedure called by the main procedure? For instance...

Private Sub DoSomething()

Try
Call DoSomethingElse()
Catch
MsgBox("An error occured.")
Finally
MsgBox("This code always executes.")
End Try

End Sub

If an error occurs in the DoSomethingElse procedure, will the error be
caught in the Try...Catch...Finally exception handler?
 
Usually yes, the procedure that is called (DosomethingElse()) would "bubble"
its exception back to the Try block.
 
Hi Jy

In addition to Scott,

Only not if in that Call is something that "end" or on another way kills the
program.

Cor
 
Further to the other answers, if DoSomethingElse() contains its own
Try..Catch block, it is possible to catch the exception and return without
causing the exception to be caught at the outer level. It depends on how you
want it to work.

HTH

Charles
 
* "jy836 said:
When using the Try...Catch...Finally statements, what happens if an error
occurs in a procedure called by the main procedure? For instance...

Private Sub DoSomething()

Try
Call DoSomethingElse()
Catch
MsgBox("An error occured.")
Finally
MsgBox("This code always executes.")
End Try

End Sub

If an error occurs in the DoSomethingElse procedure, will the error be
caught in the Try...Catch...Finally exception handler?

Yes, if it's not caught in the 'DoSomethindElse' procedure or if it's
thrown by this procedure.
 
Back
Top