Correctly handling error in instantiating class / stopping main program execution

>>The point remains valid that in order to receive the exact "Type mismatch" message, I must do local error trapping. Even in your example, the details are changed when the code passes Err.Raise.<<

Of course the error message changes, your code changes it.

Chris, you miss the point. I am not talking about my code. I am pointing out that even your code changes the Err object when the Err.Raise occurs. That is, it does NOT contain the Source and Description Err.Raise told the error to be.

In your code you have:

Code:
Err_Clear:
   MsgBox "Class: clsObjProjectsTbl, Subroutine: Clear()"
   Err.Raise vbObjectError + 1, [B][COLOR=Red]"Class: clsObjProjectsTbl, Subroutine: Class_Initialize()", "Error: Failed to instantiate class instance."[/COLOR][/B]
   Resume Exit_Clear
But what came through in the error was:

As soon as the code passes the Err.Raise LOC, the global Watch on the Err object changes to: "Error: Failed to instantiate class instance."

So even your code example does not deliver the custom message Err.Raise told the Err to be.

"Error: Failed to instantiate class instance." is better than "Automation Error"... just it is NOT the custom Err text.

The only way I found to Err.Raise and successfully receive in the caller program the custom message sent via Err.Raise was to turn off error handling, then Err.Raise a brand new Err.

That is... The way VBA / Access appear to work is:
1) Handle the exact error locally
2) Turn off error handling
3) Err.Raise a new error
In order to not have VBA tamper with the evidence.

Side note: I think perhaps if I truly wanted to raise only one error / the exact error, then one would capture into local variables all of the Err object attributes, shut off error handling, and Err.Raise a new Err object based on the saved data. I feel that such is too many LOC's in order to achieve a one MsgBox error handler.
 
>>"Error: Failed to instantiate class instance." is better than "Automation Error"... just it is NOT the custom Err text.<<

It looks like it to me, it’s in the Err.Raise line on code:-

Err.Raise vbObjectError + 1, "Class: clsObjProjectsTbl, Subroutine: Class_Initialize()", "Error: Failed to instantiate class instance."

Do you have another meaning for custom Err text?
Did you test it from the Form as I suggested?

Chris.
 
I think I know what your problem is…

You are using the global Watch to look at the Err.Description and it is not showing the Err.Source.

To make tests, please use the Form I provided.

Chris.
 
>>"Error: Failed to instantiate class instance." is better than "Automation Error"... just it is NOT the custom Err text.<<

It looks like it to me, it’s in the Err.Raise line on code:-

Err.Raise vbObjectError + 1, "Class: clsObjProjectsTbl, Subroutine: Class_Initialize()", "Error: Failed to instantiate class instance."

I apologize, at first glance I did not catch that it was more than not "Automation Error" but indeed the custom error text.

So perhaps developing the code in A2003 and the upgrading it to A2007 DB format makes the custom Err.Raise come through correctly... or or or... Very odd.

I implemented my proposed fix in #35 in ALL of the classes. In my mind it is a closed topic now. Moving onto next development tasks. Thank you.
 

Users who are viewing this thread

Back
Top Bottom