Exception handler for php to customise behavior given a specific exception code
$handler = new \Letsface\ExceptionHandler();
$handler->listen('123', function() {
return 'foo';
});
try {
throw new \MyException('', '123');
}
catch(\Exception $e) {
// will echo "foo";
echo $handler->handle($e);
}
$handler = new \Letsface\ExceptionHandler();
$handler->throws('123', new \AnotherException('My new message', 'NEWCODE'));
try {
throw new \MyException('', '123');
}
catch(\Exception $e) {
// will throw "\AnotherException";
$handler->handle($e);
}
$handler = new \Letsface\ExceptionHandler();
$handler->rethrow('123');
try {
throw new \MyException('', '123');
}
catch(\Exception $e) {
// will throw $e;
$handler->handle($e);
}