Why can’t you answer this question directly; did you test the code I posted in post #14?
Yes I did test that scenario posted in #14.
And I replied with my findings of why it was not a suitable solution to the problem.
Why can’t you answer this question directly; did you test the code I posted in post #14?
Where exactly in post #15 does it say you tested the code I posted in post #14?
Production use of my classes uses the Clear() method to reset the class to all defaults. So code itself calling Clear() would have its own error handling present, creating an instance of the object / Clear() getting in trouble, THAT I need to bomb out of the application for.
>>How do I know that? I tested that scenario.<<
That does not answer the question, the question was; did you test the code I posted in post #14?
Thus, I let Clear() take care of its own errors and only Class_Initialize() raises errors.
For now the standard I am proposing is that all methods take care of their own errors. Only in two cases do I Err.Raise
1) In code that I do not intend to have to check the return code of each call to a Class... such as my TxtFile class... I want to be able to put a lot of calls to that class in succession without having to code error checking on a per-call basis, just Err.Raise and let the Err handler of that code escalate the Err. No matter was it the first or N'th call to the TxtFile class, the general error handler is good enough protection... I do not need customized error handling beyond what is already provided. (Which that was the thread I referenced in my OP)
2) Now in Class_Initialize() it appears to be helpful to capture failed initialization of class instances.
Private Sub Class_Initialize()
Me.Clear
End Sub
Public Sub Clear()
On Error GoTo Err_Clear
Dim intA As Integer
intA = 1 + "A"
Exit_Clear:
Exit Sub
Err_Clear:
MsgBox "Class: clsObjProjectsTbl, Subroutine: Clear()"
Err.Raise vbObjectError + 1, "Class: clsObjProjectsTbl, Subroutine: Class_Initialize()", "Error: Failed to instantiate class instance."
Resume Exit_Clear
End Sub
I think what Chris is asking is did you test the actual code as it appears above, or did you simply take a part of it and just test that part.Code:Private Sub Class_Initialize() Me.Clear End Sub Public Sub Clear() [B] [COLOR=Red]On Error GoTo Err_Clear[/COLOR][/B] Dim intA As Integer intA = 1 + "A" Exit_Clear: Exit Sub Err_Clear: MsgBox "Class: clsObjProjectsTbl, Subroutine: Clear()" [B][COLOR=Red]Err.Raise vbObjectError + 1, "Class: clsObjProjectsTbl, Subroutine: Class_Initialize()", "Error: Failed to instantiate class instance."[/COLOR][/B] Resume Exit_Clear End Sub
As encouraging as it was to read that... it still did not articulate that trying to propagate an error to be handled by the caller will result in the error information being overwritten by "Automation Error" when program control is returned to the caller.I did a Google search in the *.vb newsgroups for anything relating to "Automation error" and "Err.Raise". There were lots! Unfortunately, there was a lot of guessing and folklore amongst the replies. Worse still, there was some absolute rubbish written about error handlers not being able to raise further errors, or handle errors incurred during their own cleanup -- but that's off-topic.
if the class initialise fails in some way, can you not just set some property in the class as an indicator.
I think that that is the type of answer ChrisO was wanting verified.
So lets see what ChrisO has to say now that that point has been cleared up.
I can't see why you did not reply like this earlier.![]()
![]()
On Error GoTo 0
Private Sub Class_Initialize()
Me.Clear
End Sub
'This is a generic API that clears all of the field attributes
Public Sub Clear()
On Error GoTo Err_Clear
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"
Exit_Clear:
Exit Sub
Err_Clear:
Call errorhandler_MsgBox("Class: clsObjProjectsTbl, Subroutine: Clear()")
'Disable further error handling. Since the code was already handling an error, if we raised the error without first
'turning it off, that would result in an "Automation Error" aka Double Trap
On Error GoTo 0
'Raise the error to the caller program
Err.Raise Number:=vbObjectError + 1, _
Source:="Class: clsObjProjectsTbl, Subroutine: Clear()", _
Description:="Failed to Clear() class instance"
Resume Exit_Clear
End Sub
The code you posted in post #31 does not raise an "Automation Error" for me.
Please see the Access 2003 attachment.
The code you posted in post #31 does not raise an "Automation Error" for me.