2019-04-10 18:59:26 +02:00
|
|
|
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) {
|
2019-06-03 12:23:42 +02:00
|
|
|
ExceptionHandler::printException($e);
|
2019-04-10 18:59:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class NewException extends Exception {
|
|
|
|
}
|
|
|
|
|
|
|
|
class Program {
|
|
|
|
|
2019-05-17 08:40:41 +02:00
|
|
|
public void main() {
|
2019-04-10 18:59:26 +02:00
|
|
|
callback $handler = void(Exception $e) {
|
|
|
|
ExceptionHandler::handleException($e);
|
|
|
|
};
|
|
|
|
set_exception_handler($handler);
|
2019-06-05 08:23:13 +02:00
|
|
|
try {
|
|
|
|
print("Called try block 0\n");
|
|
|
|
} finally {
|
|
|
|
print("Called finally block 0\n");
|
|
|
|
}
|
2019-04-10 18:59:26 +02:00
|
|
|
try {
|
|
|
|
throw new NewException("Catch me once", 1);
|
|
|
|
} catch(Exception $e) {
|
|
|
|
ExceptionHandler::handleException($e);
|
2019-06-04 07:39:30 +02:00
|
|
|
} finally {
|
|
|
|
print("Called finally block 1\n");
|
2019-04-10 18:59:26 +02:00
|
|
|
}
|
2019-06-05 08:23:13 +02:00
|
|
|
try {
|
|
|
|
throw new NewException("Catch me twice", 2);
|
|
|
|
} finally {
|
|
|
|
print("Called finally block 2\n");
|
|
|
|
}
|
|
|
|
throw new Exception("Catch me thrice", 3);
|
2019-04-10 18:59:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|