C ++ primer Reading Notes (12)

Source: Internet
Author: User

Standard exception classes in C ++


Namespace std

{

// Exception Derivation

Class logic_error; // logical error, which can be detected before running the program.


// Logic_error is derived.

Class domain_error; // The precondition is violated.

Class invalid_argument; // specifies an invalid parameter of the function.

Class length_error; // an attempt to point out an object that exceeds the maximum value of the present value of the size_t type

Class out_of_range; // parameter out of bounds

Class bad_cast; // an invalid dynamic_cast expression exists in the runtime type recognition.

Class bad_typeid; // report has a null pointer P in expression test typeid (* P)

// Exception Derivation

Class runtime_error; // runtime error, detected only during program running

// Runtime_error Derivation

Class range_error; // violates the post Condition

Class overflow_error; // report an arithmetic Overflow

Class bad_alloc; // Storage Allocation Error

}

 

Observe the hierarchy of the above classes. We can see that all standard exceptions are derived from a common base class exception. The base class contains necessary polymorphism functions that provide exception descriptions and can be overloaded. The following is the prototype of the exception class:

Class exception

{

Public:

Exception () Throw ();

Exception (const exception & RHs) Throw ();

Exception & operator = (const exception & RHs) Throw ();

Virtual ~ Exception () Throw ();

Virtual const char * What () const throw ();

};

One of the important functions is what (), which returns a string pointer indicating an exception.

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.