Home > Backend Development > C++ > body text

Should You Use Exception Specifiers in C ?

Patricia Arquette
Release: 2024-11-04 00:19:03
Original
926 people have browsed it

 Should You Use Exception Specifiers in C  ?

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!