downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/function.set-exception-handler.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/ref.errorfunc.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'function.set-exception-handler.php',
   
1 => 'set_exception_handler',
  ),
 
'up' =>
  array (
   
0 => 'ref.errorfunc.php',
   
1 => 'Error Handling Functions',
  ),
 
'prev' =>
  array (
   
0 => 'function.set-error-handler.php',
   
1 => 'set_error_handler',
  ),
 
'next' =>
  array (
   
0 => 'function.trigger-error.php',
   
1 => 'trigger_error',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="function.set-exception-handler" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">set_exception_handler</h1>
  <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">set_exception_handler</span> &mdash; <span class="dc-title">
   Sets a user-defined exception handler function
  </span></p>

 </div>

 <a name="function.set-exception-handler.description"></a><div class="refsect1 description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type"><a href="language.pseudo-types.php#language.types.callback" class="type callback">callback</a></span> <span class="methodname"><b>set_exception_handler</b></span>
    ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.php#language.types.callback" class="type callback">callback</a></span> <tt class="parameter">$exception_handler</tt></span>
   )</div>

  <p class="para rdfs-comment">
   Sets the default exception handler if an exception is not caught within a
   try/catch block. Execution will stop after the
   <i><tt class="parameter">exception_handler</tt></i>
 is called.
  </p>
 </div>


 <a name="function.set-exception-handler.parameters"></a><div class="refsect1 parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   </p><dl>

    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">exception_handler</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       Name of the function to be called when an uncaught exception occurs.
       This function must be defined before calling
       <b>set_exception_handler()</b>. This handler function
       needs to accept one parameter, which will be the exception object that
       was thrown.
      </p>
     </dd>

   
   </dl>
<p>
  </p>
 </div>


 <a name="function.set-exception-handler.returnvalues"></a><div class="refsect1 returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the name of the previously defined exception handler, or <b><tt class="constant">NULL</tt></b> on error. If
   no previous handler was defined, <b><tt class="constant">NULL</tt></b> is also returned.
  </p>
 </div>


 <a name="function.set-exception-handler.examples"></a><div class="refsect1 examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   </p><div class="example">
    <p><b>Example #1 <b>set_exception_handler()</b> example</b></p>
    <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">exception_handler</span><span style="color: #007700">(</span><span style="color: #0000BB">$exception</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Uncaught&nbsp;exception:&nbsp;"&nbsp;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$exception</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getMessage</span><span style="color: #007700">(),&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">set_exception_handler</span><span style="color: #007700">(</span><span style="color: #DD0000">'exception_handler'</span><span style="color: #007700">);<br /><br />throw&nbsp;new&nbsp;</span><span style="color: #0000BB">Exception</span><span style="color: #007700">(</span><span style="color: #DD0000">'Uncaught&nbsp;Exception'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"Not&nbsp;Executed\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div><p>
  </p>
 </div>


 <a name="function.set-exception-handler.seealso"></a><div class="refsect1 seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   </p><ul class="simplelist">
    <li class="member"><a href="function.restore-exception-handler.php" class="function" rel="rdfs-seeAlso">restore_exception_handler()</a> - Restores the previously defined exception handler function</li>
    <li class="member"><a href="function.restore-error-handler.php" class="function" rel="rdfs-seeAlso">restore_error_handler()</a> - Restores the previous error handler function</li>
    <li class="member"><a href="function.error-reporting.php" class="function" rel="rdfs-seeAlso">error_reporting()</a> - Sets which PHP errors are reported</li>
    <li class="member">information about the <a href="language.pseudo-types.php#language.types.callback" class="link">callback</a> type</li>
    <li class="member"><a href="language.exceptions.php" class="link">PHP 5 Exceptions</a></li>
   </ul><p>
  </p>
 </div>


</div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites