Created
December 9, 2013 15:30
-
-
Save unusorin/7874001 to your computer and use it in GitHub Desktop.
Errors as exceptions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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