<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Switch on/off exception throwing</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="yaf-dispatcher.sleep.html">Yaf_Dispatcher::__sleep</a></div> <div class="next" style="text-align: right; float: right;"><a href="yaf-dispatcher.wakeup.html">Yaf_Dispatcher::__wakeup</a></div> <div class="up"><a href="class.yaf-dispatcher.html">Yaf_Dispatcher</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="yaf-dispatcher.throwexception" class="refentry"> <div class="refnamediv"> <h1 class="refname">Yaf_Dispatcher::throwException</h1> <p class="verinfo">(Yaf >=1.0.0)</p><p class="refpurpose"><span class="refname">Yaf_Dispatcher::throwException</span> — <span class="dc-title">Switch on/off exception throwing</span></p> </div> <div class="refsect1 description" id="refsect1-yaf-dispatcher.throwexception-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type"><a href="class.yaf-dispatcher.html" class="type Yaf_Dispatcher">Yaf_Dispatcher</a></span> <span class="methodname"><strong>Yaf_Dispatcher::throwException</strong></span> ([ <span class="methodparam"><span class="type">bool</span> <code class="parameter">$flag</code></span> ] )</div> <p class="para rdfs-comment"> Siwtch on/off exception throwing while unexpected error occurring. When this is on, Yaf will throwing exceptions instead of triggering catchable errors. </p> <p class="para"> You can also use <a href="yaf.appconfig.html#configuration.yaf.dispatcher.throwexception" class="link"> application.dispatcher.throwException</a> to achieve the same purpose. </p> </div> <div class="refsect1 parameters" id="refsect1-yaf-dispatcher.throwexception-parameters"> <h3 class="title">Parameters</h3> <dl> <dt> <span class="term"><em><code class="parameter">flag</code></em></span> <dd> <p class="para"> bool </p> </dd> </dt> </dl> </div> <div class="refsect1 returnvalues" id="refsect1-yaf-dispatcher.throwexception-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> </p> </div> <div class="refsect1 examples" id="refsect1-yaf-dispatcher.throwexception-examples"> <h3 class="title">Examples</h3> <div class="example" id="example-4131"> <p><strong>Example #1 <span class="function"><strong>Yaf_Dispatcher::throwexception()</strong></span>example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /><br />$config </span><span style="color: #007700">= array(<br /> </span><span style="color: #DD0000">'application' </span><span style="color: #007700">=> array(<br /> </span><span style="color: #DD0000">'directory' </span><span style="color: #007700">=> </span><span style="color: #0000BB">dirname</span><span style="color: #007700">(</span><span style="color: #0000BB">__FILE__</span><span style="color: #007700">),<br /> ),<br />);<br /></span><span style="color: #0000BB">$app </span><span style="color: #007700">= new </span><span style="color: #0000BB">Yaf_Application</span><span style="color: #007700">(</span><span style="color: #0000BB">$config</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$app</span><span style="color: #007700">-></span><span style="color: #0000BB">getDispatcher</span><span style="color: #007700">()-></span><span style="color: #0000BB">throwException</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /><br />try {<br /> </span><span style="color: #0000BB">$app</span><span style="color: #007700">-></span><span style="color: #0000BB">run</span><span style="color: #007700">();<br />} catch (</span><span style="color: #0000BB">Yaf_Exception $e</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$e</span><span style="color: #007700">-></span><span style="color: #0000BB">getMessage</span><span style="color: #007700">());<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> string(59) "Could not find controller script /tmp/controllers/Index.php" </pre></div> </div> </div> <div class="example" id="example-4132"> <p><strong>Example #2 <span class="function"><strong>Yaf_Dispatcher::throwexception()</strong></span>example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /><br />$config </span><span style="color: #007700">= array(<br /> </span><span style="color: #DD0000">'application' </span><span style="color: #007700">=> array(<br /> </span><span style="color: #DD0000">'directory' </span><span style="color: #007700">=> </span><span style="color: #0000BB">dirname</span><span style="color: #007700">(</span><span style="color: #0000BB">__FILE__</span><span style="color: #007700">),<br /> ),<br />);<br /></span><span style="color: #0000BB">$app </span><span style="color: #007700">= new </span><span style="color: #0000BB">Yaf_Application</span><span style="color: #007700">(</span><span style="color: #0000BB">$config</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$app</span><span style="color: #007700">-></span><span style="color: #0000BB">getDispatcher</span><span style="color: #007700">()-></span><span style="color: #0000BB">throwException</span><span style="color: #007700">(</span><span style="color: #0000BB">false</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$app</span><span style="color: #007700">-></span><span style="color: #0000BB">run</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> PHP Catchable fatal error: Yaf_Application::run(): Could not find controller script /tmp/controllers/Index.php in /tmp/1.php on line 12 </pre></div> </div> </div> </div> <div class="refsect1 seealso" id="refsect1-yaf-dispatcher.throwexception-seealso"> <h3 class="title">See Also</h3> <ul class="simplelist"> <li class="member"> <span class="methodname"><a href="yaf-dispatcher.catchexception.html" class="methodname" rel="rdfs-seeAlso">Yaf_Dispatcher::catchException()</a> - Switch on/off exception catching</span></li> <li class="member"><a href="class.yaf-exception.html" class="classname">Yaf_Exception</a></li> </ul> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="yaf-dispatcher.sleep.html">Yaf_Dispatcher::__sleep</a></div> <div class="next" style="text-align: right; float: right;"><a href="yaf-dispatcher.wakeup.html">Yaf_Dispatcher::__wakeup</a></div> <div class="up"><a href="class.yaf-dispatcher.html">Yaf_Dispatcher</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>