== Why is this an issue?

The catch-all handler, written `+catch(...)+` in {cpp}, or `+@catch(...)+` in Objective-C, catches every type of exception. If there is another catch statement for a specific exception after the catch-all handler, it will not be executed because the catch-all handler will already have handled the exception.

== How to fix it

=== Code examples

The following {cpp} example is similar in Objective-C: the `try` and `catch` equivalents are `@try` and `@catch`.

==== Noncompliant code example

[source,cpp]
----
void f() {
  try {
    // ...
  } catch (...) {
    // Handle all exception types
  } catch (std::exception const &e) { // Noncompliant: it will never be called
  }
}
----

==== Compliant solution

[source,cpp]
----
void f() {
  try {
    // ...
  } catch (std::exception const &e) {
    // Handle standard exceptions
  } catch (...) { // Compliant: handle all other exception types
  }
}
----


== Resources

=== Documentation

* {cpp} reference - https://en.cppreference.com/w/cpp/language/try_catch[try-block]
* Apple Developer Documentation - https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Exceptions/Tasks/HandlingExceptions.html[Objective-C: Handling Exceptions]

=== External coding guidelines

* MISRA {cpp}:2008, 15-3-7 - Where multiple handlers are provided in a single try-catch statement or function-try-block, any ellipsis (catch-all) handler shall occur last.


ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

=== is related to: S1045

=== on 30 Jan 2020, 16:25:41 Nicolas Harraudeau wrote:
This rule has little value for python as Python interpreter will raise a ``++SyntaxError++``.

endif::env-github,rspecator-view[]
