Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The first one should never be used in production code, since it's transporting information irrelevant to end-users (a user can't do anything about <em>"Cannot connect to database"</em>).</p> <p>You throw Exceptions if you know that at a certain critical code point, your application <em>can fail</em> and you want your code to recover across multiple call-levels.</p> <p><code>trigger_error()</code> lets you fine-grain error reporting (by using different levels of error messages) and you can hide those errors from end-users (using <a href="http://php.net/manual/en/function.set-error-handler.php" rel="noreferrer"><code>set_error_handler()</code></a>) but still have them be displayed to you during testing.</p> <p>Also <code>trigger_error()</code> can produce non-fatal messages important during development that can be suppressed in production code using a custom error handler. You can produce fatal errors, too (<code>E_USER_ERROR</code>) but those aren't recoverable. If you trigger one of those, program execution <em>stops</em> at that point. This is why, for fatal errors, Exceptions should be used. This way, you'll have more control over your program's flow:</p> <pre><code>// Example (pseudo-code for db queries): $db-&gt;query('START TRANSACTION'); try { while ($row = gather_data()) { $db-&gt;query('INSERT INTO `table` (`foo`,`bar`) VALUES(?,?)', ...); } $db-&gt;query('COMMIT'); } catch(Exception $e) { $db-&gt;query('ROLLBACK'); } </code></pre> <p>Here, if <code>gather_data()</code> just plain croaked (using <code>E_USER_ERROR</code> or <code>die()</code>) there's a chance, previous <code>INSERT</code> statements would have made it into your database, even if not desired and you'd have no control over what's to happen next.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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