By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,854 Members | 2,004 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,854 IT Pros & Developers. It's quick & easy.

Class returns 440 - automation error

P: n/a
Hello,

I know this must be something simple I'm overlooking but I can't get
err.raise inside a class to return anything but 440 - automation
error. For example, if I create the following test class:

Option Compare Database
Option Explicit

Private Sub Class_Initialize()

On Error GoTo Errhandler

Err.Raise vbObjectError + 70004, "User.Initialize"

Exit Sub

Errhandler:

Err.Raise Err.Number, Err.Source, Err.Description

End Sub

and then use the following code to test it:

Sub testitout()

Dim x As clsTest

On Error GoTo Errhandler

Set x = New clsTest

Exit Sub

Errhandler:

Err.Raise Err.Number, Err.Source, Err.Description

End Sub

When I call testitout() from the debug window I get an error message
saying 'run time error 440: automation error' instead of my custom
error. What do I need to do to have the caller of my class raise my
custom error instead of the generic 440 automation error? Thanks.

Bruce

Feb 16 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a

Bruce wrote:
Hello,

I know this must be something simple I'm overlooking but I can't get
err.raise inside a class to return anything but 440 - automation
error. For example, if I create the following test class:

Option Compare Database
Option Explicit

Private Sub Class_Initialize()

On Error GoTo Errhandler

Err.Raise vbObjectError + 70004, "User.Initialize"

Exit Sub

Errhandler:

Err.Raise Err.Number, Err.Source, Err.Description

End Sub

and then use the following code to test it:

Sub testitout()

Dim x As clsTest

On Error GoTo Errhandler

Set x = New clsTest

Exit Sub

Errhandler:

Err.Raise Err.Number, Err.Source, Err.Description

End Sub

When I call testitout() from the debug window I get an error message
saying 'run time error 440: automation error' instead of my custom
error. What do I need to do to have the caller of my class raise my
custom error instead of the generic 440 automation error? Thanks.

Bruce

I see that you are trying to raise an error 3 times in your code, but
you are not trying to do anything with it.
Your error number would be -2147151500 which I don't think is a
recognized number and since you are not doing anything with that
number ( ex. no MsgBox statement ) Access applies the Automation Error
message. The class is in effect an automation object and there was an
error in it. You need to spend a little more time reading into some of
the tips and tricks of error handling.
You example should look more like

---------------------------------------------------------------
Private Sub Class_Initialize()
On Error GoTo Errhandler

Err.Raise vbObjectError + 70004, "User.Initialize"

exit_here:
Exit Sub

Errhandler:
MsgBox Err.Description, vbOKCancel, Err.Number & " in " &
Err.Source
'Err.Raise Err.Number, Err.Source, Err.Description 'Commented
out
Resume exit_here
End Sub

-------------------------------------------------

Sub testitout()

Dim x As clsTest

On Error GoTo Errhandler

Set x = New clsTest

exit_here:
Set x = Nothing
Exit Sub

Errhandler:
Resume exit_here
'Err.Raise Err.Number, Err.Source, Err.Description 'Commented
out
End Sub

Feb 18 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.