PC Review


Reply
Thread Tools Rate Thread

ArgumentOutOfRangeException

 
 
=?Utf-8?B?V2VzdGU=?=
Guest
Posts: n/a
 
      13th Nov 2007
I am throwing the ArgumentOutOfRangeException in my code as shown below

throw new ArgumentOutOfRangeException("value", "Value must be > 0");

my catch block is below

catch(ArgumentOutOfRangeException exception)
{
MessageBox.Show(exception.Message,"Input Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);

} // end catch

My question is the message box shows both my custom error of "Value must be
> 0. and paramamter name=value. Why is it displaying parameter name when all

I am requesting is the exception.Message? Thanks for your help.
 
Reply With Quote
 
 
 
 
Marc Gravell
Guest
Posts: n/a
 
      13th Nov 2007
Simply because that is how ArgumentOutOfRangeException chooses to
format it's inner message when a parameter name is supplied; can't
really do much about it unless you a: don't supply the param-name, b:
reformat it, or c: catch the specific type and display your own
message:

string actualMsg =
new ArgumentOutOfRangeException("ParamName",
"MyMessage").Message;

gives:
MyMessage[crlf]
Parameter name: ParamName

Marc


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ArgumentOutOfRangeException shapper Microsoft C# .NET 4 27th Oct 2009 08:55 AM
ArgumentOutOfRangeException - Parameter name:due Tm =?Utf-8?B?R3JhY2U=?= Microsoft Dot NET 0 15th Feb 2006 09:19 PM
ArgumentOutOfRangeException arujgeorge@gmail.com Microsoft ASP .NET 1 10th Dec 2005 12:09 AM
Rowfilter ArgumentOutOfRangeException Thomas Usselman Microsoft Dot NET Compact Framework 1 2nd Oct 2003 07:13 AM
ArgumentOutOfRangeException Zahid Microsoft Dot NET Compact Framework 0 24th Sep 2003 11:15 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:24 PM.