The fifth Chapter C + +: Statements related to the introduction

Source: Internet
Author: User
Tags exception handling

Fifth Chapter Statement

Pendant else

The question of how to find a matching if branch for else when the if branch is hiding from the Else branch:
-C + + stipulates that else matches the not-so-recent if match, which eliminates the two semantics.

Switch

Switch (CH) {case    ' a ': Case    ' B ':        ++n;        break;}
    • Break jumps out of the switch control flow.

    • The case label (case lable) must be an integer constant expression .

    • If a case label succeeds, all branches will be executed sequentially from the label, unless the interrupt is shown, until the end of switch is stopped.

    • The statement after the case label, with curly braces ({}), defines the variable within the block, ensuring that all subsequent case labels are outside the scope of the variable.

    • Default tag: A special case label that executes the contents of the default tag when switch does not match all cases.

Do While

Do    statementwhile (condition);  Note Semicolon
    • Defining variables within a loop condition is not allowed.

    • And the variables of the conditional part must be defined outside the loop body.

Jump statement

    • Break

      is responsible for terminating the while, do, and for or switch statements that are closest to it, and starting with the first statement after the statements.

    • Continue

      For, while, do and

Try statement block and exception handling

    • throw-expression (Throw expression): The Exception detection section uses a throw expression to indicate that it has encountered an issue that cannot be handled.

      • Called throw** (Raise) an exception.

      • After an exception is thrown, the function is terminated and control is transferred to the code that can handle the exception.

    • try Block (try block): Try to start with one or more catch clauses (catch clause) end.

      • Exceptions that are thrown by code in a try statement block are usually handled by a catch clause.

      • The catch clause is called the Exception handling code (exception handler).

    • Exception classes (Exception Class)

try {    //program-statements} catch (/*exception-declaration exception declaration */) {    //handler-statements} catch (/* exception-declaration*/) {    //handler-statements}//...
    • An exception declaration specifies the type of exception that the catch clause can handle.

Standard exceptions

The C + + standard library defines a set of classes that report problems encountered by standard library functions.
In the following 4 header files:
-Exception: Defines the most common exception class exception, which only reports the occurrence of exceptions and does not provide any additional information.
-Stdexcept
-Class with a string object or a C-style literal.
-Only one member function what ()

exception //最常见的问题
runtime_error //只有在运行时才能检测出的问题
overflow_error //
underflow_error
logic_error
domain_error
invalid_arguement
length_error
out_og_range

-New:bad_alloc
-Type_info:bad_cast

Reference: C++primer Fifth Edition

Related articles:

Fourth C + +: Application of expression concept-operator

sixth C + +: Function basics and application

Related Article

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.