The Usage of Exception Specifiers in C
Question:
Should exception specifiers be employed in C programming?
Answer:
No.
Reasons:
-
Lack of Enforcement: Compilers do not strictly enforce exception specifiers, making their benefits questionable.
-
Termination on Violation: Non-compliance with specifiers typically leads to program termination, which is not always desirable.
-
Inconsistency in Visual Studio: Visual Studio treats throw(X) as throw(...), compromising adherence to the standard.
-
Template Restrictions: Exception specifications hinder the creation of template code as they cannot accommodate exceptions that may occur during execution.
-
Prohibition of Extensibility: Exception specifications limit code extensibility by requiring explicit specification of potential exceptions, which may not be known or foreseeable.
-
Issues with Legacy Code: Libraries may throw unknown exceptions, rendering exception specifiers unreliable in such scenarios.
-
Recommended Approach: Returning common errors as values while reserving exceptions for exceptional circumstances is a more practical approach.
The above is the detailed content of Should You Use Exception Specifiers in C ?. For more information, please follow other related articles on the PHP Chinese website!
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn