A thought occurred to me today to leverage some prior learnings in order to determine if a Class had an error completing its Class_Initialize() Subroutine which does not support a return code. Learnings were as follows:
"How to raise error in class method such that calling code will be notified of err"
http://www.access-programmers.co.uk/forums/showthread.php?t=234958#post1198646
So I coded up an error within Class_Initialize() as follows:
I have marked the bug I planted.
So I tested it, indeed program execution was halted as the parent's error handler correctly received error notification that the class object could not be created. As follows:
Now, in the Form_main \ Form_Load() error report, I do not see the error information which was escalated to it. It is as if Form_Load() has no idea why it is diverting execution into its own error handler. I would have expected the blue text to show up somewhere, no?
Did I code my Err.Raise incorrectly then?
"How to raise error in class method such that calling code will be notified of err"
http://www.access-programmers.co.uk/forums/showthread.php?t=234958#post1198646
So I coded up an error within Class_Initialize() as follows:
Code:
Private Sub Class_Initialize()
'Clear the class attributes
Me.Clear
End Sub
'This is a generic API that clears all of the field attributes
Public Sub Clear()
On Error GoTo Err_Clear
[B][COLOR=Red]Dim intA As Integer[/COLOR][/B]
Me.id = 0
Me.authid = 0
Me.authusername = vbNullString
Me.logtimestamp = vbNullString
Me.title = vbNullString
Me.budget = 0
Me.rptactiveflg = False
Me.rpttitle = vbNullString
strFETempTableName = "tmptblqry_projects"
[B][COLOR=Red]intA = 1 + "A"[/COLOR][/B]
Exit_Clear:
Exit Sub
Err_Clear:
Call errorhandler_MsgBox("Class: clsObjProjectsTbl, Subroutine: Clear()")
'Disable further error handling, so that the code which is using this object will handle the error
On Error GoTo 0
'Raise the error to the caller program
Err.Raise -1[B][COLOR=Blue], "Class: clsObjProjectsTbl, Subroutine: Clear()"[/COLOR][/B]
Resume Exit_Clear
End Sub
So I tested it, indeed program execution was halted as the parent's error handler correctly received error notification that the class object could not be created. As follows:
Code:
Date: 20121109 Time: 10:58:16 UserID: c_mlueck
AppErrorMsg: Class: clsObjProjectsTbl, Subroutine: Clear()
Error Source: Fandango_FE
Error Number: 13
Error Description: Type mismatch
MessageText: The data is invalid.
Date: 20121109 Time: 10:58:32 UserID: c_mlueck
AppErrorMsg: Form: Form_main, Subroutine: Form_Load()
Error Source: [null]
Error Number: 0
Error Description: [null]
MessageText: The operation completed successfully.
Did I code my Err.Raise incorrectly then?