Throwing ArgumentExceptions in Property Setters

M

Mike Hofer

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!
 
R

RobinS

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.
 
M

Mike Hofer

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.











- 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!
 
R

RobinS

Mike Hofer said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top