473,321 Members | 1,622 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,321 software developers and data experts.

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

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

Nov 17 '05 #1
3 2062
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.
<ma********@yahoo.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
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

Nov 17 '05 #2


Yes, use "value" keyword. Nothing needed.

Vadivel Kumar
http://csharpblogs.blogspot.com

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #3
FxCop (at least, the version I use) insists that you pass the string
"value".

Nov 17 '05 #4

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

Similar topics

0
by: Victor Crudu | last post by:
Hi, could somebody help me to solve the follwing problem ? I get the following exception when i set as the DataSource of a DataGrid a DataTable. This situation can be only if I change...
3
by: dawn | last post by:
Hi, I have written a bot-like program, which basically does the same thing over and over again, only using different parameters. Everything goes fine, until after an hour or three, the...
2
by: Nony Buz | last post by:
My objective is simply: Notify a form when a image file has been created in a directory. First there is a basic interface for the callback function: public interface INewImageNotify { void...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
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...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
6
by: =?Utf-8?B?QkJN?= | last post by:
Hi, I have an app that is crashing due to a System.ArgumentException. At this point it's just a simple app to test some basic object values. The main app is a Windows App that looks like...
3
by: ohmmega | last post by:
since its common knowledge that it's not possible to hide a tabcontrol tab, i made a collection for removed pages including their tabcontrols. removing works pretty fine, but whenever i try to add...
4
by: Vlad | last post by:
I am having problems using the file.create method within a function that is called when looping through an array of filepaths. If I call my function with a hardcoded file path --C:\Temp.txt the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.