Skip to content

Instantly share code, notes, and snippets.

@unusorin
Created December 9, 2013 15:30
Show Gist options
  • Save unusorin/7874001 to your computer and use it in GitHub Desktop.
Save unusorin/7874001 to your computer and use it in GitHub Desktop.
Errors as exceptions
<?php
class PhpErrorException extends \Exception{
public function __construct($message = "", $code = 0, $file = '', $line = '', Exception $previous = null)
{
$this->file = $file;
$this->line = $line;
parent::__construct($message, $code, $previous);
}
}
set_error_handler(function($number,$message,$file,$line){
throw new PhpErrorException($message, $number, $file, $line);
});
try{
echo $asd0;
}catch(PhpErrorException $e){
echo "An error occured".PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment