Exception handling in C#

Posted on 2006-04-20
Last Modified: 2008-03-06

When I try to raise exceptions like the one below

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

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

I can I handle this. pls help
Question by:sureshraina
    LVL 10

    Expert Comment

    try this:

    throw(new Exception("Test"));
    LVL 23

    Expert Comment

    Applications should be using ApplicationException object.

    Author Comment

    The following exception types are too general to provide sufficient information to the user:

    The following exception types are reserved and should be thrown only by the common language runtime:

    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
    LVL 23

    Accepted Solution

    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(".....");

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now