Files
Aer/tests/exception_handler.aer
T

45 lines
1012 B
Plaintext

import 'console';
class ExceptionHandler {
public static void printException(Exception $e) {
Console::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 {
Console::Print("Called try block 0\n");
} finally {
Console::Print("Called finally block 0\n");
}
try {
throw new NewException("Catch me once", 1);
} catch(Exception $e) {
ExceptionHandler::handleException($e);
} finally {
Console::Print("Called finally block 1\n");
}
try {
throw new NewException("Catch me twice", 2);
} finally {
Console::Print("Called finally block 2\n");
}
throw new Exception("Catch me thrice", 3);
}
}