Exception handling in C#

Hello,

When I try to raise exceptions like the one below

                              if (reader.FieldCount < 2)
            {
                  ReportError(new Exception("should select atleast 2"),"");
                  return;
            }

I am getting an errror saying "Do not raise reserved exception types"

I can I handle this. pls help
sureshrainaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aki4uCommented:
try this:

throw(new Exception("Test"));
0
naveenkohliCommented:
Applications should be using ApplicationException object.
0
sureshrainaAuthor Commented:
The following exception types are too general to provide sufficient information to the user:

System.Exception
System.ApplicationException
System.SystemException
The following exception types are reserved and should be thrown only by the common language runtime:

System.ExecutionEngineException
System.IndexOutOfRangeException
System.NullReferenceException
System.OutOfMemoryException
How to Fix Violations
To fix a violation of this rule, change the type of the thrown exception to a specific type that is not one of the reserved types.


How do I fix this even after using applicationexception object it is throwing hte same eroro
0
naveenkohliCommented:
As it is being suggedted by your coding rules... you should be using one of the specific execption types and not the general type exception.
I guess in your case, since argument value range is wrong you can throw something like.

throw new ArgumentException(".....");
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.