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 2 5436
"Bogdan Zamfir" <bz*****@despam med.com> wrote in message
news:2n******** ****@uni-berlin.de... 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?
The logic of what you are doing is correct, buit there are questions about
the
code you posted.
Do you have Option Explicit declared?
Where is MyVal declared and what does it have to do with anything? Maybe
it's
a typo and should be someVal.
The following code, a complete runnable version based on what you posted,
does exactly what you would expect it to do.
<clsErrTest>
Option Compare Database
Option Explicit
Dim cMyProp As String
Property Let MyProp(ByVal SomeVal As String)
If SomeVal = "" Then
Err.Raise _
vbObjectError + 1000, _
"Let property MyProp", _
"Property does not accept empty string"
Else
cMyProp = SomeVal
End If
End Property
</clsErrTest>
<test procedure>
Sub TestclsErrTest( )
Dim myObj As clsErrTest
Set myObj = New clsErrTest
On Error GoTo Errhand
myObj.MyProp = "" ' this should raise the error
MsgBox Err.Description
exitHere:
If Not myObj Is Nothing Then
Set myObj = Nothing
End If
Exit Sub
Errhand:
MsgBox Err.Description & vbCrLf & _
"The code should (?) get here after assigning empty string to " & _
"MyProp, but it doesn't"
Resume exitHere
End Sub
</test procedure>
Hi,
Thank you for your reply
Yes, your code worked, and mine not, till I noticed a thing
About your questions, I typed that code as an example in the post, and not
copy from my real code, and indeed I have option explicit and MyVal should
be SomeVal
However, after I looked to your code and to mine (the real one), I noticed I
have a on error resume next few lines above the raise statement
And I didn't reset it with other on error statement. Actually, my issue was
the Someval should be a printer name, and I use it to get a reference to a
valid printer object. And I use on error resume next just before the code
on error resume next
set oMyPrinter = printers(SomeVa l)
if oMyPrinter is nothing then
...(bla, bla)
And it seems this on error resume next was the problem,
But as I know, when I left the sub with on error resume next statement, the
error handling should be automatically restored to setting from calling sub,
isn't it?
But in my case it didn't restored, and this caused the error not to be
raised.
Anyway, I found and fixed this, and thank you for your post.
Cheers
Bogdan
"rkc" <rk*@yabba.dabb a.do.rochester. rr.bomb> wrote in message
news:cU******** *********@twist er.nyroc.rr.com ... "Bogdan Zamfir" <bz*****@despam med.com> wrote in message news:2n******** ****@uni-berlin.de... 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?
The logic of what you are doing is correct, buit there are questions about the code you posted.
Do you have Option Explicit declared? Where is MyVal declared and what does it have to do with anything? Maybe it's a typo and should be someVal.
The following code, a complete runnable version based on what you posted, does exactly what you would expect it to do.
<clsErrTest> Option Compare Database Option Explicit
Dim cMyProp As String
Property Let MyProp(ByVal SomeVal As String) If SomeVal = "" Then Err.Raise _ vbObjectError + 1000, _ "Let property MyProp", _ "Property does not accept empty string" Else cMyProp = SomeVal End If End Property
</clsErrTest>
<test procedure> Sub TestclsErrTest( )
Dim myObj As clsErrTest Set myObj = New clsErrTest On Error GoTo Errhand
myObj.MyProp = "" ' this should raise the error MsgBox Err.Description
exitHere: If Not myObj Is Nothing Then Set myObj = Nothing End If Exit Sub
Errhand: MsgBox Err.Description & vbCrLf & _ "The code should (?) get here after assigning empty string to " & _ "MyProp, but it doesn't" Resume exitHere
End Sub </test procedure>
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Remy C. Cool |
last post by:
Hello,
My application uses a remote import scheme using the sys.path_hooks
solution as explained in PEP302
(http://www.python.org/peps/pep-0302.html)
The importer works fine for packages, modules, modules in packages and
packages in packages, but there's a problem when a module in a package
want's to import a module from the same package.
|
by: Chris S. |
last post by:
A wrote a small class to handle IO through pipes, but the connection
only seems to work in one direction. The following code defines
connection.py, engine.py, and controller.py. Once connected, the engine
is only able to send and the controller recieve. Also, this only works
when using popen2.popen3. Using os.popen3 doesn't work at all and...
|
by: steven |
last post by:
Hi,
Anyone was using pmock for unit testing with python? I met a problem
and hope someone to help me. For short, the pmock seems can not mock a
iterator object.
For example, the tested object is foo, who need to send message to
another object bar. So, to test the foo, I need mock a mockBar. But
the bar is a iterator, the foo use the...
|
by: virgo81 |
last post by:
hi~
I made smartclient.
First, I made a StrongNamed Key(snk file).
I add my key file and set allow partiallytrustedcllers.
|
by: Ralph Soons |
last post by:
Hi all,
I am trying to save the viewstate in a session instead of storing it in a
hidden of the webpage which is default. This because of performance reasons.
When I use line 2 in combination with line 4, my application works. Using
Line 1 in combination with line 3 (and of course renaming httpSessionState1
to httpSessionState) results in...
| |
by: francois |
last post by:
Hi guys,
I have quite big troublesome performance problem.
then i did a very simpkle page with a dropdownlist, when u click on it it
makes a simple sql select on the SQL server and then display a very little
bit of data on the page.
When SQL server runs on my local machine it is pretty fast, but when SQL
server runs on our production...
|
by: Wei Wang |
last post by:
I get compile error for this code:
for i in 1..arg_count-1 LOOP
RAISE NOTICE quote_literal(to_char(i, ''9''));
END LOOP;
where arg_count = 3.
I tried RAISE NOTICE to_char(i, ''9''); as well.
|
by: Dmitry Prokoptsev |
last post by:
Hello,
I need to write a class for exceptions which can be thrown, caught,
stored and thrown once again. I have written the following code:
--- begin ---
#include <string>
class Exception {
public:
|
by: Martin |
last post by:
Hi all,
I'm having a problem when trying to raise an event in my custom control when
a toolstripbutton enable state changes. The problem is that although the
code to raise the event executes, my handler never see it.
This executes when the button enable state changes:-
Private Sub OnPrintToolStripButton_EnabledChanged(ByVal sender As...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |