diff --git a/rules/S1181/cfamily/rule.adoc b/rules/S1181/cfamily/rule.adoc index 25757b72b1..86da35ff78 100644 --- a/rules/S1181/cfamily/rule.adoc +++ b/rules/S1181/cfamily/rule.adoc @@ -1,13 +1,13 @@ == Why is this an issue? -Some exception classes are designed to be used only as base classes to more specific exceptions, for instance ``++std::exception++`` (the base class of all standard {cpp} exceptions), ``++std::logic_error++`` or ``++std::runtime_error++``. +Some exception classes are designed to be used only as base classes to more specific exceptions, for instance, ``++std::exception++`` (the base class of all standard {cpp} exceptions), ``++std::logic_error++`` or ``++std::runtime_error++``. -Catching such a generic exception types is a usually bad idea, because it implies that the "catch" block is clever enough to handle any type of exception. +Catching such generic exception types is usually a bad idea because it implies that the "catch" block is clever enough to handle any type of exception. === Noncompliant code example -[source,cpp] +[source,cpp,diff-id=1,diff-type=noncompliant] ---- try { /* code that may throw std::system_error */ @@ -18,7 +18,7 @@ try { === Compliant solution -[source,cpp] +[source,cpp,diff-id=1,diff-type=compliant] ---- try { /* code that may throw std::system_error */ @@ -29,14 +29,14 @@ try { === Exceptions -There are cases though where you want to catch all exceptions, because no exceptions should be allowed to escape the function, and generic ``++catch++`` handlers are excluded from the rule: +There are cases, though, where you want to catch all exceptions because no exceptions should be allowed to escape the function, and generic ``++catch++`` handlers are excluded from the rule: * In the main function -* In a class destructor +* In a class destructor * In a ``++noexcept++`` function * In an ``++extern "C"++`` function -Additionally, if the ``++catch++`` handler is throwing an exception (either the same as before, with ``++throw;++`` or a new one that may make more sense to the callers of the function), or is never exiting (because it calls a ``++noreturn++`` function, for instance ``++exit++``), then the accurate type of the exception usually does not matter any longer: this case is excluded too. +Additionally, if the ``++catch++`` handler is throwing an exception (either the same as before, with ``++throw;++`` or a new one that may make more sense to the callers of the function) or is never exiting (because it calls a ``++noreturn++`` function, for instance ``++exit++``), then the accurate type of the exception usually does not matter any longer: this case is excluded too. == Resources