class ExceptionHandler { public static void printException(Exception $e) { print('Uncaught ' + get_class($e) + ', code: ' + $e->getCode() + "\nMessage: " + htmlentities($e->getMessage()) + "\n"); } public static void handleException(Exception $e) { ExceptionHandler::printException($e); } } class NewException extends Exception { } class Program { public void main() { callback $handler = void(Exception $e) { ExceptionHandler::handleException($e); }; set_exception_handler($handler); try { print("Called try block 0\n"); } finally { print("Called finally block 0\n"); } try { throw new NewException("Catch me once", 1); } catch(Exception $e) { ExceptionHandler::handleException($e); } finally { print("Called finally block 1\n"); } try { throw new NewException("Catch me twice", 2); } finally { print("Called finally block 2\n"); } throw new Exception("Catch me thrice", 3); } }