Design principle-----function returns an error or throws an exception

Source: Internet
Author: User

See StackOverflow on the answer, is the software upper (relative) components recommend the use of exceptions, low-level (relative) components recommend that the function return error code (if it is pure C, then the return error code is positive, the more independent module components, it is recommended to use the error code). Obviously, the return error code is relatively simple, but it will be difficult to maintain later on, and of course, it is not absolute.

Http://stackoverflow.com/questions/253314/exceptions-or-error-codes

Of course, this has to be a matter of opinion, not uniform bias with one. Here are a few community discussions that are better discussed:

http://www.iteye.com/problems/59997

http://star.baidu.com/forum/forum.php?mod=viewthread&tid=412

How to use C + + exceptions:

http://blog.csdn.net/renwotao2009/article/details/6751687

Of course, the exception has a very obvious benefit, that is, the caller of the function will not forget the check return value. Because there is no need. If you simply return the error message, what if the return value is not checked? Then once the error occurs, the program will continue to run and enter an indeterminate state.

Design principle-----function returns an error or throws an exception

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.