Aer/tests/exception_handler.aer
belliash 55acf8111f
All checks were successful
The build was successful.
Assume private visibility for all class members by default.
In most (all?) modern OOP languages class members visibility is assumed to be private and programmer has to consciously set it to public or protected. PHP has the different approach what can cause a security flaws in written scripts. AerScript will not follow this way, as it seems to be conceptually broken.
2019-05-17 08:40:41 +02:00

34 lines
676 B
Plaintext

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) {
self::printException($e);
}
}
class NewException extends Exception {
}
class Program {
public void main() {
callback $handler = void(Exception $e) {
ExceptionHandler::handleException($e);
};
set_exception_handler($handler);
try {
throw new NewException("Catch me once", 1);
} catch(Exception $e) {
ExceptionHandler::handleException($e);
}
throw new Exception("Catch me twice", 2);
}
}