What to put in paramName of ArgumentException when throwing from a property?

  • Thread starter Thread starter marcstober
  • Start date Start date
M

marcstober

Hello, I have some code like:

public int MyProperty {
set {
if (value < 0) {
throw new ArgumentOutOfRangeException("??paramName??",
"Value must be positive.")
}
_myProperty = value;
}
}

(Obviously this is just an example to illustrate the question.)

The question is what should I pass to the ArgumentOutOfRange
constructor for the "paramName" parameter? There really isn't a
parameter name with properties -- there's the "value" keyword, or do I
use the name of the property?

Thanks, Marc
 
Well you can put whatever makes sense but I usually just use "value" since
it is, technically, the name of the parameter. The exception is really just
for other developers (along with the call stack) and so they should be able
to understand the message means.
 

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

Back
Top