title: How to catch exceptions in your ZF2 controllers?
body: <p>I've setup the <a href="https://github.com/zendframework/ZendSkeletonApplication" rel="noreferrer">ZendSkeletonApplication</a> with <code>ZF 2.0.3</code> and I am unable to catch exceptions in my controllers. For instance if I put the below piece of code in <code>module/Application/src/Application/Controller/IndexController.php</code>:</p>
  <pre><code>public function indexAction() {
      echo &quot;BEFORE\n&quot;;
      try {
          throw new \Exception(&quot;My exception&quot;);
      } catch (Exception $e) {
          echo &quot;Caught exception $e\n&quot;;
          exit;
      }
  </code></pre>
  <p>and access the page I get:</p>
  <pre><code>BEFORE
  An error occurred
  An error occurred during execution; please try again later.
  Additional information:
  Exception
  
  File:
  
      module/Application/src/Application/Controller/IndexController.php:25
  
  Message:
  
      My exception
  </code></pre>
  <p>the <code>ViewModel</code> kicks in and displays the exception, effectively preventing me from catching it.</p>
  <p><strong>How can I catch exceptions in <code>ZF2</code> controllers?</strong></p>