Chapter 3 Exception Handling in C ++

Source: Internet
Author: User

Preface:

The exception mechanism is added to C ++ as a new feature of the language. Java exception handling is originated from C ++ exception handling. Despite exceptions

C ++ has been introduced for a long time, but C ++CommunityThere are still many people writingProgramWhen you do not use exceptions, some people do not know how to be correct

Usage exception. So far, there is no widely accepted conventional technology, so that when exceptions are thrown, the software can be more predictable and stable.

 

Exceptions are not logical errors, so we need to be clear about them. The program runs well when exceptions exist because they are

Instead of running well. Abnormal and safeCodeIt was not written by luck. It was a software design that did not consider the exception mechanism.

The probability that a program can run correctly when an exception occurs and that a software that is not designed for multi-thread execution can be correctly executed in the case of multiple threads.

The probability is the same, almost zero.

 

C LanguageThe error code meets the needs of C programmers. This error code is usually a global variable or returns

Error status code. In this way, the caller of the function must manually check the return value to determine whether the function is successfully executed. This is of course not very convenient.

. At the same time, exception handling also increases program overhead. However, you can set the disable exception through the options during compilation.

 

The following chapters briefly describe how to write exceptional security code. Pay attention to the principles in these chapters to make your software more correct,

It is more robust and efficient, and you can avoid many problems that are frequently encountered during usage 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.