Throwing an exception during startup or shutdown results in an implementation-defined termination of the program. This is because there is no where to put ``++try++``/``++catch++`` blocks to catch exceptions thrown in the startup phase, when static objects are being constructed, or during the shutdown phase, when those static objects are being destroyed.


Therefore exceptions should not be thrown during the construction or destruction of static objects.


== Noncompliant Code Example

----
class C 
{

  public: 
    C ( ) 
    {
      throw ( 0 ); // Noncompliant; thrown before main starts 
    }
    ~C ( ) 
    { 
      throw ( 0 ); // Noncompliant; thrown after main exits 
    } 
};

C c; // An exception thrown in C's constructor or destructor will 
     // cause the program to terminate, and will not be caught by 
     // the handler in main

int main( ... ) 
{ 
  // ...
----


== See

* MISRA {cpp}:2008, 15-3-1


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

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