stranno
06-21-2013, 03:06 AM
Hi,
please, have a look at this Error Handling method. This seems not to be consistent with the following explanation:
"If your procedure calls another procedure, the On Error Resume Next statement becomes inactive
during the execution of the called procedure. Therefore, you should place an On Error Resume Next
statement in each called procedure that needs one. This is necessary because the Resume Next
behavior applies only to the procedure containing the On Error Resume Next statement. If an
unhandled error occurs in a called procedure, the exception propagates back to the calling procedure,
and execution resumes on the statement following the call. In such cases, the error is not handled."
Or am i wrong?
Sub ErrorHandling()
On Error GoTo ErrHandling 'For non fatale errors which do need to be mentioned
MsgBox 1 / 0
MsgBox "Non Fatale Error 1 handled by ErrHandling"
Call Hulp
MsgBox 1 / 0
MsgBox "Non Fatale Error 2 handled by ErrHandling"
Call Hulp
On Error Resume Next 'For non fatale errors which don't need to be mentioned
MsgBox 1 / 0
MsgBox "This error 3 should/must not be mentioned and is also not handled by ErrHandling or Stoppen"
Call Hulp
On Error GoTo 0
On Error GoTo ErrHandling
Call Hulp
On Error GoTo Stoppen 'For fatale errors which do need to be mentioned after that the process will be stopped
MsgBox 1 / 0
On Error GoTo 0
Call Hulp
MsgBox "This code will not be executed"
On Error GoTo 0
Exit Sub
ErrHandling:
MsgBox "What : " & Err.Description _
& Chr(10) & Chr(13) & "Where : " & "ErrorHandling", vbInformation, "Error: " & Err.Number
Resume Next
Exit Sub
Stoppen:
MsgBox "What : " & Err.Description _
& Chr(10) & Chr(13) & "Where : " & "ErrorHandling" _
& Chr(10) & Chr(13) & Chr(13) & "The process will be stopped", vbCritical, "Error: " & Err.Number
'release objects etc.
End Sub
Sub Hulp()
MsgBox "Hello, this is Hulp"
MsgBox 1 / 0
End Sub
Tip: Use F8 for execution
Regards, Stranno
please, have a look at this Error Handling method. This seems not to be consistent with the following explanation:
"If your procedure calls another procedure, the On Error Resume Next statement becomes inactive
during the execution of the called procedure. Therefore, you should place an On Error Resume Next
statement in each called procedure that needs one. This is necessary because the Resume Next
behavior applies only to the procedure containing the On Error Resume Next statement. If an
unhandled error occurs in a called procedure, the exception propagates back to the calling procedure,
and execution resumes on the statement following the call. In such cases, the error is not handled."
Or am i wrong?
Sub ErrorHandling()
On Error GoTo ErrHandling 'For non fatale errors which do need to be mentioned
MsgBox 1 / 0
MsgBox "Non Fatale Error 1 handled by ErrHandling"
Call Hulp
MsgBox 1 / 0
MsgBox "Non Fatale Error 2 handled by ErrHandling"
Call Hulp
On Error Resume Next 'For non fatale errors which don't need to be mentioned
MsgBox 1 / 0
MsgBox "This error 3 should/must not be mentioned and is also not handled by ErrHandling or Stoppen"
Call Hulp
On Error GoTo 0
On Error GoTo ErrHandling
Call Hulp
On Error GoTo Stoppen 'For fatale errors which do need to be mentioned after that the process will be stopped
MsgBox 1 / 0
On Error GoTo 0
Call Hulp
MsgBox "This code will not be executed"
On Error GoTo 0
Exit Sub
ErrHandling:
MsgBox "What : " & Err.Description _
& Chr(10) & Chr(13) & "Where : " & "ErrorHandling", vbInformation, "Error: " & Err.Number
Resume Next
Exit Sub
Stoppen:
MsgBox "What : " & Err.Description _
& Chr(10) & Chr(13) & "Where : " & "ErrorHandling" _
& Chr(10) & Chr(13) & Chr(13) & "The process will be stopped", vbCritical, "Error: " & Err.Number
'release objects etc.
End Sub
Sub Hulp()
MsgBox "Hello, this is Hulp"
MsgBox 1 / 0
End Sub
Tip: Use F8 for execution
Regards, Stranno