Statements are fully suitable for C ++ code. Exceptions and other error handling mechanisms are not really intended for claims.
Error handling is when it is possible to correctly repair or report a problem to the user. For example, if there is an error while trying to read the input file, you can do something about it. Errors can occur due to errors, but they can also be just the appropriate output for a given input.
Claims are for things like checking API compliance, when the API is not usually checked, or to verify that the developer believes that he guarantees the construction. For example, if an algorithm requires sorted input, you would usually not check for this, but you might have a statement to test it so that debugging creates a flag for such an error. The statement always indicates an incorrectly running program.
If you are writing a program where an unclean shutdown can cause a problem, you can avoid claims. Undefined behavior strictly in terms of the C ++ language cannot be regarded as a problem here, since the assertion is probably already the result of Undefined behavior or violation of some other requirement that could prevent some cleaning from the correct operation.
Also, if you implement statements in terms of exclusion, you can potentially catch and handle it, even if it contradicts the very purpose of the statement.
bames53 Aug 21 '12 at 20:18 2012-08-21 20:18
source share