Thread: Error handling
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Erik Wikström[_2_] Erik Wikström[_2_] is offline
external usenet poster
 
Posts: 4
Default Error handling

I am quite new to VBA programming and I have come across a problem when
dealing with errors. Comming from a C++ background I am most familiar with
exceptions and I was wondering if there is some way to "rethrow" an erro once
it has been handled? Something like:

Sub Foo()
On Error GoTo E:
Bar
Baz
Exit Sub

E:
If Err.Number = 11 Then
Resume Next
Else
ReThrow Err
End If
End Sub

Imagine for example that sometimes Bar will try to divide by zero, and if
that happens it is safe to resume and execute Baz. But if some other kind of
error should happen I do not want to handle it here.

I know that I can use 'Error Err.Number' or Err.Raise to "create" a new
error in the else-block, but while developing it would be nice to have the
original error to simplify debugging (since the debugger can show me where
the error occurred).

--
Erik Wikström