B
Bogdan Zamfir
Hi,
I have a problem with err.raise
I write a class module, and I want to use this mechanism to indicate errors
when user set wrong values to properties
But it seems the error is never raised (although, when I exit from the
property let code, if I check err.number and message, I get the error
message I set in err.raise statement
But my calling code never throw me into error handler if I set wrong
property value
To be more specific:
This is the code in my class
dim cMyProp as string
property Let MyProp (byval SomeVal as string)
if MyVal ="" then
err.raise Err.Raise vbObjectError + 1000, "Let property MyProp",
"Property does not accept empty string"
else
cMyProp = Someval
endif
end property
And in another module I have this code
.....
on error goto Errhand
TestLine: myObj.MyProp = "" ' this should raise the error
debug.print err.description
exit sub
Errhand:
MsgBox "The code should (?) get here after assigning empty string to
MyProp, but it doesn't"
....
So when I execute TestLine, from my understanding, the prop should raise the
error and my code should jump to err handler
But this isn't happening
Although, if I test myself err.number and message exactly after TestLine, it
contains the error I try to raise.
How to handle this? Should I test everytime the err.number and
err.description in such cases?
Thank you
I have a problem with err.raise
I write a class module, and I want to use this mechanism to indicate errors
when user set wrong values to properties
But it seems the error is never raised (although, when I exit from the
property let code, if I check err.number and message, I get the error
message I set in err.raise statement
But my calling code never throw me into error handler if I set wrong
property value
To be more specific:
This is the code in my class
dim cMyProp as string
property Let MyProp (byval SomeVal as string)
if MyVal ="" then
err.raise Err.Raise vbObjectError + 1000, "Let property MyProp",
"Property does not accept empty string"
else
cMyProp = Someval
endif
end property
And in another module I have this code
.....
on error goto Errhand
TestLine: myObj.MyProp = "" ' this should raise the error
debug.print err.description
exit sub
Errhand:
MsgBox "The code should (?) get here after assigning empty string to
MyProp, but it doesn't"
....
So when I execute TestLine, from my understanding, the prop should raise the
error and my code should jump to err handler
But this isn't happening
Although, if I test myself err.number and message exactly after TestLine, it
contains the error I try to raise.
How to handle this? Should I test everytime the err.number and
err.description in such cases?
Thank you