The catch-all handler should come last in a chain of ``++catch++`` or ``++@catch++`` statements because it catches everything, and any more-specific ``++catch++``/``++@catch++`` that comes after it will never be used, even when the relevant condition occurs. 


This {cpp} code sample is very similar to the Objective-C equivalent with ``++@try++`` and ``++@catch++``.


== Noncompliant Code Example

----
void f1()
{
  try
  {
    // ...
  }
  catch (...)
  {
    // Handle all exception types
  }
  catch (std::exception const &e)  // Noncompliant - handler will never be called
  {
  }
}
----


== Compliant Solution

----
void f1()
{
  try
  {
    // ...
  }
  catch (std::exception const &e)  // Compliant
  {
    // Handle standard exceptions
  }
  catch (...)        // Compliant catch-all handler
  {
    // Handle all other exception types
  }
}
----


== See

* 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)

include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]
