C ++ Exception Handling Mechanism

Source: Internet
Author: User

Exception, usually refersProgramIt may be detected that the operation is abnormal, such as Division by 0, out-of-bounds access to the array, and memory depletion. The exception handling syntax is usually

Try
{
Throw()
}

Catch ()
{
}

The keyword try and the content in braces after it are called try blocks. Simply put, it contains the places where errors may occur (that is, the places we want to detect ). When an error message is detected, throw the keyword throw. What should we do? Where can I leave it? Our catch keyword solves this problem for us. Catch is usually used to receive exceptions thrown by throw. Note that the type thrown by throw must match the type accepted by catch.
Throw expressions act like function calls, while catch Clauses Act Like function definitions. One of the main differences between the two mechanisms is:All the information required to create a function call is obtained at the time of compilation, but the exception handling mechanism is not. C ++ exception handling requires runtime support.

Http://www.cnblogs.com/8586/archive/2009/05/28/1491288.html
Catch (...) can catch all types of 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.