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 use the noexcept exception indicator of Clippers 11

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article introduces the knowledge of "how to use the noexcept exception indicator of Clippers 11". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

C++ exception handling

Exception handling (exception handing) enables problem detection and handling to be carried out separately, which is one of the important language features of C++ suitable for large-scale development. First of all, let's give a brief explanation.

First, suppose we have a function testfun () that throws some kind of Error.

Note: C++ does not require that the object thrown must be exception,Error. It can be of any type.

For this error, if the code is not handled, once the testfun is called, the program aborts and produces the following output:

Even a little more serious software will not accept this result. So the general choice is to handle this error, that is, to use the try/catch mechanism to catch the error.

Testfun2,testfun3 calls testfun internally, but the difference is that error traps are carried out internally in testfun2; testfun3 itself does not do error trapping, but by the main function. There is nothing wrong with either way. A more general statement is:

The program can perform error trapping at any level of processing, and if there is no error capture at all levels, the program will abort when the error occurs.

Noexcept exception indicator

Another aspect of the flexibility brought about by the above approach is that it also brings uncertainty. With the increasing scale of software development and the increasing levels of calls to function libraries / class libraries, it becomes more and more difficult to determine whether a call will throw an exception. As one of the solutions, noexcept eleven declares that handling will not throw an exception through the handler specifier. In this way, programmers do not have to go deep into all call levels to confirm themselves.

For example, testfun2 () above has already done error trapping inside it and can be defined as follows:

In this way, users can rest assured that they are bold enough not to catch errors.

Exception

One exception is that the actual internal handling throws an exception when it is clearly declared that a processing is noexcept. In this case, even if error trapping is performed, it will not work properly.

In the above code, if testfun4 () is declared as noexcept and an exception is thrown, even if try/catch cannot catch Error in the main function. If the noexcpt declaration is removed, the error catching code in the main function will work properly.

Once a process is declared to be noexcept, the compiler also seems to omit that part of the error passing function when processing this part of the code.

This is the end of the content of "how to use the noexcept exception indicator of Clippers 11". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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

Internet Technology

Wechat

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

12
Report