In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you an analysis of how to throw exceptions on C++. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
C++ language, like other programming languages, also includes exception handling. Here we will explain in detail the implementation and application of exceptions thrown by C++. I hope you can get some help to improve your understanding.
C++ throws an exception (also known as discarding exception), that is, it detects whether an exception is generated. In C++, it uses throw statement to achieve, and if an exception is detected, an exception is thrown. The format of the statement is:
Throw expression
If an exception is found in the program segment of the try statement block (including the function called in it) and the exception is discarded, the exception can be caught and handled by some catch statement after the try statement block, provided that the type of the abandoned exception matches the exception type of the catch statement. Because C++ uses data types to distinguish different exceptions, the value of the expression in the throw statement has no practical meaning when judging the exception, and the type of expression is particularly important.
Handles exceptions with a divisor of 0. In this example, the above exception with divisor 0 can be caught by try/catch statement, and throw statement can be used to realize C++ throwing exception, so as to achieve exception handling. The code is shown in the code listing.
# include / / contains the header file # include double fuc (double x, double y) / / defines the function {if (y _ blank _ 0) {throw y; / / if the divisor is 0, throw an exception} return x _ blank; / / otherwise return the quotient of two numbers} void main () {double res; try / / define the exception {res=fuc (2heli3); 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.