Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you want to use exceptions instead of errors for your entire application, you can do it with <a href="http://php.net/ErrorException" rel="noreferrer">ErrorException</a> and a custom error handler (see the ErrorException page for a sample error handler). The only downside to this method is that non-fatal errors will still throw exceptions, which are always fatal unless caught. Basically, even an <code>E_NOTICE</code> will halt your entire application if your <a href="http://php.net/error_reporting" rel="noreferrer">error_reporting</a> settings do not suppress them.</p> <p>In my opinion, there are several benefits to using ErrorException:</p> <ol> <li>A custom exception handler will let you display nice messages, even for errors, using <a href="http://php.net/set_exception_handler" rel="noreferrer">set_exception_handler</a>.</li> <li>It does not disrupt existing code in any way... <a href="http://php.net/trigger_error" rel="noreferrer">trigger_error</a> and other error functions will still work normally.</li> <li>It makes it really hard to ignore stupid coding mistakes that trigger <code>E_NOTICE</code>s and <code>E_WARNING</code>s.</li> <li><p>You can use <code>try</code>/<code>catch</code> to wrap code that may generate a PHP error (not just exceptions), which is a nice way to avoid using the <code>@</code> error suppression hack:</p> <pre><code>try { $foo = $_GET['foo']; } catch (ErrorException $e) { $foo = NULL; } </code></pre></li> <li><p>You can wrap your entire script in a single <code>try</code>/<code>catch</code> block if you want to display a friendly message to your users when any uncaught error happens. (Do this carefully, because only uncaught errors and exceptions are logged.)</p></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload