Advertisement
Guest User

Untitled

a guest
May 22nd, 2010
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. <?php
  2. class errorhandler
  3. {
  4.     var $debug_level = 0;
  5.  
  6.     function __construct($debug_level = 0)
  7.     {
  8.         // Populate class variables
  9.         $this->debug_level = $debug_level;
  10.  
  11.         // Take over from PHP error handling
  12.         set_error_handler(array($this, 'handle_error'));
  13.     }
  14.  
  15.     function handle_error($type, $string, $file, $line, $vars)
  16.     {
  17.         // Decide which type of error it is, and handle appropriately
  18.         switch ($type)
  19.         {
  20.             // Error type
  21.             case FATAL:
  22.             // Select debug level
  23.             switch ($this->debug_level)
  24.             {
  25.                 default:
  26.                 case 0:
  27.                     echo 'Error: '.$string.' in '.$file.' on line'. $line.'<br />';
  28.                     print_r($var);
  29.                     // Stop application
  30.                     exit;
  31.                 case 1:
  32.                     echo 'There has been an error. Sorry for the inconvenience.';
  33.                     // Stop application
  34.                     exit;
  35.             }
  36.             case ERROR:
  37.             echo '<pre><b>ERROR</b> ['.$type.'] '.$string.'<br />'."</pre>n";
  38.             break;
  39.             case WARNING:
  40.             echo '<pre><b>WARNING</b> ['.$type.'] '.$string.'<br />'."</pre>n";
  41.             break;
  42.         }
  43.     }
  44. }
  45.  
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement