title: How to "catch" a handled exception in a class from the script using the the class?
body: <p>I have a script that looks like this:</p>
  
  <pre><code>require ("class-pdowrapper.php");
  $db = new DB();
  
  $baddata = 'abc'; //should be an integer!!
  
  $db-&gt;bind("myinteger", $baddata);
  $sql = "INSERT INTO t_numbers (theinteger) VALUES (:myinteger)";
  $result = $db-&gt;query($sql);
  
  if ($result == 1) {
      echo "success.";
  } else {
      echo "didn't work..."; //question relates to this line
  }
  </code></pre>
  
  <p>If <code>$baddata</code> is "abc" i.e. a string, the class will handle the exception and output something like this:</p>
  
  <blockquote>
    <p>Unhandled Exception. 
    SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'abc' for column 'theinteger' at row 1
    You can find the error back in the log</p>
  </blockquote>
  
  <p>The class does this by something like:</p>
  
  <pre><code>private function query($statement) {
      try {
          // stuff
      }
      catch (PDOException $e) {
          echo $this-&gt;ExceptionLog($e-&gt;getMessage(), $query);
          die();
      } 
  }
  
  
  
  private function ExceptionLog($message, $sql = "") {
          $exception = 'Unhandled Exception. &lt;br /&gt;';
          $exception .= $message;
          $exception .= "&lt;br /&gt; You can find the error back in the log.";
  
          if (!empty($sql)) {
              $message .= "\r\nRaw SQL : " . $sql;
          }
          return $exception;
  }
  </code></pre>
  
  <p>So the question is, how can a script acknowledge the exception thrown and handled in the class and use the knowledge to do something. In my case, I could show the user an error or email the administrator to show that something isn't working with the database-related code.</p>