Previous version of the similar question: Error handling in class returns runtime error 440 "automation error"
There's a class ClsSubject
. It has a property called INN
. When letting a value into .INN the class checks wheither:
1) the value is a numeric string and
2) the value is exactly 10 characters long.
Otherwise it throws an error. Here's the code of class module:
Option Explicit
Private PINN As String
Property Let INN(val As String)
If IsNumeric(val) And Len(val) = 10 Then
PINN = val
Else
Dim ErrorNum As Long
ErrorNum = 513
Dim MessageDescripton As String
MessageDescripton = val & " is not a valid value"
Err.Raise ErrorNum, "ClsSubject", MessageDescripton
End If
End Property
Property Get INN() As String
INN = PINN
End Property
The debugging code in the main module:
Sub Test()
Dim I As New ClsSubject
I.INN = 99
End Sub
Expected outcome: Error 513 "99 is not a valid value"
Actual outcome: Error 513 "Application-defined or Object-defined error"
P.S. I tried to change the error number of error by adding vbObjectError
value to it like this:
ErrorNum = vbObjectError + 513
But this gives me Runtime error -2147220991 (80040201) Automation Error: An even was unable to invoke any of the subscribers
P.P.S.: Since the question is getting no-repro, here's an additional information. The code is written in MS Excel 2010 standard, version 14.0.6023.1000 (32 bit). The workbook contains no code other than mentioned above. The screenshots: