Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to learn more about C++ exception handling

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you how to in-depth understanding of C++ exception handling, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.

Basic exception handling

Exception handling mechanism: suspend problem handling, not in the current function, but in his caller (get on the bus first, then make up the ticket)

What is an exception: anything can be thought of as an exception, and an error is just a kind of exception.

Once an exception is thrown, it is not handled. If an exception is thrown, the default abort function is called to terminate the program.

Catch and handle exceptions:

Throw throws an exception: (the value is of any type, but it's just a reference for us to handle the exception, similar to the return value.)

Try (check, catch) and catch (handle exceptions): must appear together, and their parentheses {} cannot be omitted

Tip: anything can be thought of as an exception, and an error is just one of the exceptions-there is a situation that does not make the program work properly

How to throw an exception / / find the remainder of an and b how to throw an exception int division (int aline int b) {if (bounded in0) throw 0; / / throw a value (arbitrary)-- > and then deal with return a cout b;} void print (int a line int b) {cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report