letsface/php-error-handler

Exception handler for php to customise behavior given a specific exception code

v1.2 2015-07-24 03:59 UTC

This package is not auto-updated.

Last update: 2024-04-17 08:02:59 UTC


README

Exception handler for php to customise behavior given a specific exception code

Usage

Custom handler

$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);
}

Throw an exception

$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);
}

Rethrow the exception

$handler = new \Letsface\ExceptionHandler();
$handler->rethrow('123');

try {
  throw new \MyException('', '123');
}
catch(\Exception $e) {
  // will throw $e;
  $handler->handle($e);
}