473,405 Members | 2,262 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Throwing ArgumentExceptions in Property Setters

Quick question.

When you guys throw an ArgumentException (or one of its deriviatives)
from a property setter, what do you use as the argument to the
exception's constructor? For instance:

Throw New ArgumentOutOfRangeException("value")

Passing "value" seems less helpful than it should be; you have to
examine the call stack to determine which property threw the
exception. I am sorely tempted in many cases to use the name of the
property, but I know that this isn't the recommended practice.

On the other hand, I've considered a series of exception classes
similar to ArgumentException: PropertyException. These would take the
property name rather than the argument name. That way, the name
semantics are preserved and everyone's happy.

How do you guys deal with this scenario? Do you just suck it up and
use "value"?

Thanks!

Apr 23 '07 #1
3 1276
This has already been answered in another newsgroup. If you want to post to
multiple newsgroups, please post all of them at once. This way, if it gets
answered in one group, the people in the other groups can see it, and can
chime in, or know it's been answered so they can go help someone whose
question has not been answered.

Thanks,
Robin S.
-------------------------------
"Mike Hofer" <kc********@gmail.comwrote in message
news:11**********************@b58g2000hsg.googlegr oups.com...
Quick question.

When you guys throw an ArgumentException (or one of its deriviatives)
from a property setter, what do you use as the argument to the
exception's constructor? For instance:

Throw New ArgumentOutOfRangeException("value")

Passing "value" seems less helpful than it should be; you have to
examine the call stack to determine which property threw the
exception. I am sorely tempted in many cases to use the name of the
property, but I know that this isn't the recommended practice.

On the other hand, I've considered a series of exception classes
similar to ArgumentException: PropertyException. These would take the
property name rather than the argument name. That way, the name
semantics are preserved and everyone's happy.

How do you guys deal with this scenario? Do you just suck it up and
use "value"?

Thanks!

Apr 24 '07 #2
On Apr 24, 3:02 am, "RobinS" <Rob...@NoSpam.yah.nonewrote:
This has already been answered in another newsgroup. If you want to post to
multiple newsgroups, please post all of them at once. This way, if it gets
answered in one group, the people in the other groups can see it, and can
chime in, or know it's been answered so they can go help someone whose
question has not been answered.

Thanks,
Robin S.
-------------------------------"Mike Hofer" <kchighl...@gmail.comwrote in message

news:11**********************@b58g2000hsg.googlegr oups.com...
Quick question.
When you guys throw an ArgumentException (or one of its deriviatives)
from a property setter, what do you use as the argument to the
exception's constructor? For instance:
Throw New ArgumentOutOfRangeException("value")
Passing "value" seems less helpful than it should be; you have to
examine the call stack to determine which property threw the
exception. I am sorely tempted in many cases to use the name of the
property, but I know that this isn't the recommended practice.
On the other hand, I've considered a series of exception classes
similar to ArgumentException: PropertyException. These would take the
property name rather than the argument name. That way, the name
semantics are preserved and everyone's happy.
How do you guys deal with this scenario? Do you just suck it up and
use "value"?
Thanks!- Hide quoted text -

- Show quoted text -
Hi Robin,

Normally, I don't cross-post, and certainly not manually. Please
forgive me for doing so. I use Google to peruse groups at work, and
when I posted the question to the other group, it didn't appear for
*hours*. I assumed Google ate the post. So I reposted it here.

I'll go look for it over there.

Thanks!

Apr 25 '07 #3

"Mike Hofer" <kc********@gmail.comwrote in message
news:11**********************@n35g2000prd.googlegr oups.com...
On Apr 24, 3:02 am, "RobinS" <Rob...@NoSpam.yah.nonewrote:
>This has already been answered in another newsgroup. If you want to post
to
multiple newsgroups, please post all of them at once. This way, if it
gets
answered in one group, the people in the other groups can see it, and
can
chime in, or know it's been answered so they can go help someone whose
question has not been answered.

Thanks,
Robin S.
-------------------------------"Mike Hofer" <kchighl...@gmail.comwrote
in message

news:11**********************@b58g2000hsg.googleg roups.com...
Quick question.
When you guys throw an ArgumentException (or one of its deriviatives)
from a property setter, what do you use as the argument to the
exception's constructor? For instance:
Throw New ArgumentOutOfRangeException("value")
Passing "value" seems less helpful than it should be; you have to
examine the call stack to determine which property threw the
exception. I am sorely tempted in many cases to use the name of the
property, but I know that this isn't the recommended practice.
On the other hand, I've considered a series of exception classes
similar to ArgumentException: PropertyException. These would take the
property name rather than the argument name. That way, the name
semantics are preserved and everyone's happy.
How do you guys deal with this scenario? Do you just suck it up and
use "value"?
Thanks!- Hide quoted text -

- Show quoted text -

Hi Robin,

Normally, I don't cross-post, and certainly not manually. Please
forgive me for doing so. I use Google to peruse groups at work, and
when I posted the question to the other group, it didn't appear for
*hours*. I assumed Google ate the post. So I reposted it here.

I'll go look for it over there.

Thanks!
It's okay, ship happens. I only mentioned it because I think I see you here
frequently, and would hate for you to get in the habit. Plus, I was wearing
my cranky pants. No offense intended.

Robin S.
Apr 27 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Laszlo Zsolt Nagy | last post by:
My problem is about properties and the virtuality of the methods. I would like to create a property whose get and set methods are virtual. I had the same problems in Delphi before and the solution...
2
by: Lachlan Hunt | last post by:
Hi, In JavaScript 1.5, objects can use special getter and setter functions for properties. However, these only seem to be implemented in Gecko and, AFAICT, don't seem to be part of ECMAScript. ...
15
by: Prachi Dimble | last post by:
Hi, In vb.Net one can pass arguments to properties. How does one achieve it in c#? Given below is the vb.net code for passing arguments to property getters and setters.. Thanks, Prachi ...
7
by: none | last post by:
I'm trying to implement a simple repeateable property mechansism so I don't have to write accessors for every single instance variable I have. ------------ classMyObject: def __init__ (self):...
15
by: Sek | last post by:
Gurus, I am wondering whether it is right to throw an exception from a Property of an object. To get into it further, is it okay to throw exception during 'get' operation? I was searching...
112
by: mystilleef | last post by:
Hello, What is the Pythonic way of implementing getters and setters. I've heard people say the use of accessors is not Pythonic. But why? And what is the alternative? I refrain from using them...
6
by: Mike Hofer | last post by:
Okay, silly question. Nitpicky, sure, but it bugs me. Range-checking parameters in a property setter. For example, an Enum property with one of two possible values: Public Property...
2
by: Daniel Fetchinson | last post by:
Hi list, I've been following a discussion on a new way of defining getters and setters on python-dev and just can't understand what the purpose is. Everybody agreed on the dev list that this is a...
3
by: planey | last post by:
Hi, I was reading topic about setters and getters (http://www.thescripts.com/forum/thread631267.html) and wanted to ask, how they should be used? I have noticed that a general data validators suck,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
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...
0
tracyyun
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.