The exception handling mechanism can provide an effective and clear means of handling error conditions, particularly where a function needs to return both some desired result together with an indication of success or failure. However, because of its ability to transfer control back up the call tree, it can also lead to code that is difficult to understand. Hence it is required that the mechanism is only used to capture behaviour that is in some sense undesirable, and which is not expected to be seen in normal program execution.


== Noncompliant Code Example

[source,text]
----
void fn ( ) 
{ 
  try 
  { 
    if ( x < 10 ) 
    { 
      throw ( 10 ); 
    } 
    // Action "A" 
  }
  catch ( int32_t y ) // Noncompliant, confusing way of handling x < 10
  { 
    // Action "B" 
  } 
}
----


== Compliant Solution

[source,text]
----
if ( x < 10 )
{
  // Action "B"
}
else
{
  // Action "A"
}
----


