C # Custom Exceptions

Source: Internet
Author: User

  1. Inherits from the System.ApplicationException class and uses exception as the end of the custom exception class name
  2. Three constructors: A parameterless constructor, a constructor for a string argument, a string argument, an inner exception as a parameter constructor
    1   Public classmyexception:applicationexception2  {3     Private stringerror;4     PrivateException innerexception;5     //parameterless Constructors6      Publicmyexception ()7     {8         9     }Ten     //a constructor with a string argument that passes the custom exception information when the programmer uses the exception class to get exception information rather than MyException One       PublicMyException (stringMSG):Base(msg) A     { -          This. error=msg; -     } the     //constructor with a string argument and an inner exception information parameter -      PublicMyException (stringMsg,exception innerexception):Base(msg) -     { -          This. innerexception=innerexception; +          This. error=msg; -     } +      Public stringGetError () A     { at         returnerror; -     } -}
    Custom Exceptions
  3. Throw a custom exception

throw new MyException ("message");

Capture Custom exception: catch (MyException) {}

C # Custom Exceptions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.