Doesn't error handling have to be turned on for every individual subroutine, though?
With C++, if you have a function inside of a try block that throws an exception, then the exception isn't just local to the function - it goes all the way back to the try block and then to the catch block (if there is one).
With On Error Resume Next, don't you have to explicitly set it for every subroutine?
Even if you had:
Code:
Sub SomeSubThatWillError()
Err.Raise 9 ' raise subscript out of range error
End Sub
Sub Main()
On Error Resume Next
Call SomeSubThatWillError() ' this sub will error, but the error will not be caught
On Error Goto 0
' If we get here, then that means we successfully "caught"
' the error by not terminating program execution.
' But the program will never reach this point anyway.
If Err.Number > 0 Then ' there was an error
MsgBox "There was an error, but it was caught!"
Err.Clear ' clear the error
End If
End Sub
If I'm correctly remembering what I read in an article about error handling in VB, you'd have to put On Error Resume Next inside of the definition for SomeSubThatWillError(), otherwise, when you raise the error, it will cause the program execution to terminate even though the sub is within an On Error Resume Next/On Error Goto 0 block.
Then again, I could be completely wrong... =x