jlittlejohn
5/31/2013 - 2:31 PM

PHP: Exceptions

PHP: Exceptions

<?php
  try{
    $dsn = 'mysql:dbname=test;host=localhost';
    $dbh = new PDO($dsn,'username','password');
    echo 'Connected to Database';
  }catch (PDOException $e){
    echo 'Connection Failed: '.$e->getMessage();
  }catch(Exception $e){
    echo 'A Unknown Error Occurred: '.$e->getMessage();
  }
  echo 'I am still parsed, even if there was an error';
?>