<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.yaf-dispatcher.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'yaf-dispatcher.catchexception.php',
    1 => 'Yaf_Dispatcher::catchException',
    2 => 'Switch on/off exception catching',
  ),
  'up' => 
  array (
    0 => 'class.yaf-dispatcher.php',
    1 => 'Yaf_Dispatcher',
  ),
  'prev' => 
  array (
    0 => 'yaf-dispatcher.autorender.php',
    1 => 'Yaf_Dispatcher::autoRender',
  ),
  'next' => 
  array (
    0 => 'yaf-dispatcher.construct.php',
    1 => 'Yaf_Dispatcher::__construct',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/yaf/yaf_dispatcher/catchexception.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="yaf-dispatcher.catchexception" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Yaf_Dispatcher::catchException</h1>
  <p class="verinfo">(Yaf &gt;=1.0.0)</p><p class="refpurpose"><span class="refname">Yaf_Dispatcher::catchException</span> &mdash; <span class="dc-title">Switch on/off exception catching</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-yaf-dispatcher.catchexception-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">function</span> <span class="methodname"><strong>Yaf_Dispatcher::catchException</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></span> <code class="parameter">$flag</code><span class="initializer"> = null</span></span>): <span class="type"><span class="type"><a href="class.yaf-dispatcher.php" class="type Yaf_Dispatcher">Yaf_Dispatcher</a></span>|<span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></span></div>

  <p class="simpara">
   While
   <a href="yaf.appconfig.php#configuration.yaf.dispatcher.throwexception" class="link">application.dispatcher.throwException</a>
   is on (which can also be enabled by calling
   <span class="methodname"><a href="yaf-dispatcher.throwexception.php" class="methodname">Yaf_Dispatcher::throwException()</a></span>), Yaf throws
   exceptions when errors occur instead of triggering errors.
  </p>
  <p class="simpara">
   If exception catching is additionally enabled via this method (or via
   <a href="yaf.appconfig.php#configuration.yaf.dispatcher.catchexception" class="link">application.dispatcher.catchException</a>),
   all uncaught exceptions are caught and dispatched to
   <code class="literal">ErrorController::error</code>, if one is defined.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-yaf-dispatcher.catchexception-parameters">
  <h3 class="title">Параметри</h3>
  <dl>
   
    <dt><code class="parameter">flag</code></dt>
    <dd>
     <p class="simpara">
      Whether Yaf should catch uncaught exceptions and dispatch them to
      <code class="literal">ErrorController::error</code>.
     </p>
     <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
      <p class="simpara">
       Since Yaf 2.2.0, if this parameter is not given, the current state
       is returned instead.
      </p>
     </p></blockquote>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-yaf-dispatcher.catchexception-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="simpara">
   Returns the <span class="classname"><a href="class.yaf-dispatcher.php" class="classname">Yaf_Dispatcher</a></span> object itself when
   <code class="parameter">flag</code> is given, or a <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> indicating whether
   exception catching is enabled when it is not.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-yaf-dispatcher.catchexception-examples">
  <h3 class="title">Приклади</h3>
  <div class="example" id="example-1">
   <p><strong>Приклад #1 <span class="function"><strong>Yaf_Dispatcher::catchException()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php
</span><span style="color: #FF8000">/* if you defined an ErrorController like following */
</span><span style="color: #007700">class </span><span style="color: #0000BB">ErrorController </span><span style="color: #007700">extends </span><span style="color: #0000BB">Yaf_Controller_Abstract </span><span style="color: #007700">{
     </span><span style="color: #FF8000">/**
      * you can also call Yaf_Request_Abstract::getException to get the
      * uncaught exception.
      */
     </span><span style="color: #007700">public function </span><span style="color: #0000BB">errorAction</span><span style="color: #007700">(</span><span style="color: #0000BB">$exception</span><span style="color: #007700">) {
        </span><span style="color: #FF8000">/* an error occurred */
        </span><span style="color: #007700">switch (</span><span style="color: #0000BB">$exception</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getCode</span><span style="color: #007700">()) {
            case </span><span style="color: #0000BB">YAF_ERR_NOTFOUND_MODULE</span><span style="color: #007700">:
            case </span><span style="color: #0000BB">YAF_ERR_NOTFOUND_CONTROLLER</span><span style="color: #007700">:
            case </span><span style="color: #0000BB">YAF_ERR_NOTFOUND_ACTION</span><span style="color: #007700">:
            case </span><span style="color: #0000BB">YAF_ERR_NOTFOUND_VIEW</span><span style="color: #007700">:
                echo </span><span style="color: #0000BB">404</span><span style="color: #007700">, </span><span style="color: #DD0000">":"</span><span style="color: #007700">, </span><span style="color: #0000BB">$exception</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getMessage</span><span style="color: #007700">();
                break;
            default :
                </span><span style="color: #0000BB">$message </span><span style="color: #007700">= </span><span style="color: #0000BB">$exception</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getMessage</span><span style="color: #007700">();
                echo </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #DD0000">":"</span><span style="color: #007700">, </span><span style="color: #0000BB">$exception</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getMessage</span><span style="color: #007700">();
                break;
        }
     }
}
</span><span style="color: #0000BB">?&gt;</span></code></pre></div>
   </div>

   <div class="example-contents"><p>Поданий вище приклад виведе щось
схоже на:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">/* now if some error occurs, assuming accessing a non-existent controller
   (or you can throw an exception yourself): */
404:Could not find controller script **/application/controllers/No-exists-controller.php</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-yaf-dispatcher.catchexception-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="yaf-dispatcher.throwexception.php" class="methodname" rel="rdfs-seeAlso">Yaf_Dispatcher::throwException()</a> - Switch on/off exception throwing</span></li>
    <li><span class="methodname"><a href="yaf-dispatcher.seterrorhandler.php" class="methodname" rel="rdfs-seeAlso">Yaf_Dispatcher::setErrorHandler()</a> - Set error handler</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>