Link to home
Start Free TrialLog in
Avatar of sureshraina
sureshraina

asked on

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
Avatar of aki4u
aki4u

try this:

throw(new Exception("Test"));
Applications should be using ApplicationException object.
Avatar of sureshraina

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of naveenkohli
naveenkohli

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial