Gc07 this week: Exceptions

Source: Internet
Author: User
Tags switch case

Originally there were two sets of underlying databases, nf3d and GC, each of which had its own merits. In, they were working on a unified underlying library gc07 to facilitate their own practices, at the same time, do not rely too much on the DX framework set. Because the Ogre code is abnormal everywhere, it is always pulled by it, hoping to implement a set of exceptions. After two days of searching and discussion, I finally decided to give up on this idea.

It is true that exceptions have many advantages, but they also have many insurmountable difficulties in Engineering.

First, if exceptions are used to control errors, the database users are given higher requirements. Database users must consider many issues, otherwise they can only use the built-in Exception Handling (if any ). In addition, exceptions have many limitations, such as the failure to run exceptions in the analysis function.

Second, exceptions do not make the program safer. They are just a means of reminder and a special format. Switch case makes it easy to forget some errors (for example, if a few new error codes are added, you must remember to modify the original place where the function is called. If not modified, there may be no errors at the beginning, if an error occurs, it will be very serious. However, if an exception is killed, it cannot be forgotten (it is a pop-up box immediately, and the blind man will not be able to forget it ). This is an advantage of exceptions. However, neither exceptions nor SC makes the program safer. If you put your mind on this, you should think about how to write such code: even if an error occurs, everything is still normal, but the logic is wrong. To do this, we mainly rely on garbage collection and count PTR. We have to stand by the edge regardless of exceptions or returned values.

Third, exceptions can completely separate the program code from the error handling code. However, this is a benefit for a master who uses exceptions. For a lower level, it may be a nightmare. An exception thrown in an underlying library is passed to the user through an intermediate layer without catch. Sometimes, the user wants to complete some functions even though the function is incorrect. But now, everything starts after the catch. What logic is skipped in the middle? This is difficult to manage. Especially when the Code becomes more and more disordered, even if a master can ensure the security of the underlying library, can the provider of the middle layer be the same master?

Fourth, exceptions cannot span languages. Of course, seh is acceptable, but seh is not cross-platform. The exception thrown under VC cannot be caught at BCB, let alone C. In this way, when you do the wrapper of the library, you have to catch all exceptions and convert them into return values ...... Unless two people can use the same C compiler, other C ++ compilers cannot provide intermediate layer plug-ins and tools. Even vc7 and vc6 cannot work together, which is a major blow to a database that is designed as a class com structure.

Gc07 prepares to follow the return value method, implements count PTR management for the main pointer, and provides basic monitoring measures for memory. In terms of exceptions, only a small number of irrelevant exceptions are thrown in a few places that have to be thrown (fatal errors. In addition, the seh and C ++ exceptions are caught and "no Public License" processed without affecting the efficiency. For a very small number of fatal errors, record the program stack to provide as much information as possible for quick locating.

If you have any errors or deficiencies, please help me. Thank you! ^_^

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.