FancyPrairie
Programmer
Since I didn’t get any responses to my previous post (2/15/02), I assume the way I worded the question was far too complicated. Included below is code that will duplicate my problem. (You should be able to copy/paste to check it out)
Problem: If I call Main (via the debugger or whatever), Main02 reports the error and sends it up the call stack. Neither Main01 nor Main report the error again.
However, if I call Main01 (via the debugger), Main02 reports the error and Main01 gives me a runtime error on the Err.Raise statement (because Main01 is at the top of the calling stack).
Is there a way to prevent Main01 from displaying the runtime error when it is at the top of the calling stack?
Obviously, I could check "mlngErrNumber" after each call, but because of complexity and retrofitting, this isn't practical.
Option Compare Database
Option Explicit
Dim mlngErrNumber As Long
Dim mstrErrDescription As String
Function Main()
On Error GoTo ErrHandler
'blah blah blah
Call Main01 'If error raised, goto ErrHandler
'blah blah blah
ExitProcedure:
Exit Function
ErrHandler:
mlngErrNumber = Err.Number
mstrErrDescription = Err.Description
If (Err.Number > 0) Then 'If True, Error not reported yet
MyMsgBox
End If
Resume ExitProcedure
End Function
Function Main01()
On Error GoTo ErrHandler
'blah blah blah
Call Main02
'blah blah blah
ExitProcedure:
Exit Function
ErrHandler:
mlngErrNumber = Err.Number
mstrErrDescription = Err.Description
If (Err.Number > 0) Then 'If True, Error not reported yet
MyMsgBox
mlngErrNumber = mlngErrNumber + vbObjectError
End If
Err.Raise mlngErrNumber, "Main01," & Err.Source, mstrErrDescription
End Function
Function Main02()
Dim i As Integer
On Error GoTo ErrHandler
'blah blah blah
i = 6 / 0
'blah blah blah
ExitProcedure:
Exit Function
ErrHandler:
mlngErrNumber = Err.Number
mstrErrDescription = Err.Description
If (Err.Number > 0) Then 'If True, Error not reported yet
MyMsgBox
mlngErrNumber = mlngErrNumber + vbObjectError
End If
Err.Raise mlngErrNumber, "Main02," & Err.Source, mstrErrDescription
End Function
Public Function MyMsgBox()
On Error GoTo ErrHandler
'blah blah blah
MsgBox mstrErrDescription
'blah blah blah
ExitProcedure:
Exit Function
ErrHandler:
Resume ExitProcedure
End Function
Problem: If I call Main (via the debugger or whatever), Main02 reports the error and sends it up the call stack. Neither Main01 nor Main report the error again.
However, if I call Main01 (via the debugger), Main02 reports the error and Main01 gives me a runtime error on the Err.Raise statement (because Main01 is at the top of the calling stack).
Is there a way to prevent Main01 from displaying the runtime error when it is at the top of the calling stack?
Obviously, I could check "mlngErrNumber" after each call, but because of complexity and retrofitting, this isn't practical.
Option Compare Database
Option Explicit
Dim mlngErrNumber As Long
Dim mstrErrDescription As String
Function Main()
On Error GoTo ErrHandler
'blah blah blah
Call Main01 'If error raised, goto ErrHandler
'blah blah blah
ExitProcedure:
Exit Function
ErrHandler:
mlngErrNumber = Err.Number
mstrErrDescription = Err.Description
If (Err.Number > 0) Then 'If True, Error not reported yet
MyMsgBox
End If
Resume ExitProcedure
End Function
Function Main01()
On Error GoTo ErrHandler
'blah blah blah
Call Main02
'blah blah blah
ExitProcedure:
Exit Function
ErrHandler:
mlngErrNumber = Err.Number
mstrErrDescription = Err.Description
If (Err.Number > 0) Then 'If True, Error not reported yet
MyMsgBox
mlngErrNumber = mlngErrNumber + vbObjectError
End If
Err.Raise mlngErrNumber, "Main01," & Err.Source, mstrErrDescription
End Function
Function Main02()
Dim i As Integer
On Error GoTo ErrHandler
'blah blah blah
i = 6 / 0
'blah blah blah
ExitProcedure:
Exit Function
ErrHandler:
mlngErrNumber = Err.Number
mstrErrDescription = Err.Description
If (Err.Number > 0) Then 'If True, Error not reported yet
MyMsgBox
mlngErrNumber = mlngErrNumber + vbObjectError
End If
Err.Raise mlngErrNumber, "Main02," & Err.Source, mstrErrDescription
End Function
Public Function MyMsgBox()
On Error GoTo ErrHandler
'blah blah blah
MsgBox mstrErrDescription
'blah blah blah
ExitProcedure:
Exit Function
ErrHandler:
Resume ExitProcedure
End Function