From 08307c5ad65e29f800a06a57b5d8eaf8ce339d42 Mon Sep 17 00:00:00 2001 From: belliash Date: Wed, 10 Apr 2019 18:59:26 +0200 Subject: [PATCH] Let's test exceptions. --- tests/exception_handler.aer | 33 +++++++++++++++++++++++++++++++++ tests/exception_handler.exp | 4 ++++ 2 files changed, 37 insertions(+) create mode 100644 tests/exception_handler.aer create mode 100644 tests/exception_handler.exp diff --git a/tests/exception_handler.aer b/tests/exception_handler.aer new file mode 100644 index 0000000..3d3a82f --- /dev/null +++ b/tests/exception_handler.aer @@ -0,0 +1,33 @@ +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 { + + 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); + } + +} + + diff --git a/tests/exception_handler.exp b/tests/exception_handler.exp new file mode 100644 index 0000000..8310cc2 --- /dev/null +++ b/tests/exception_handler.exp @@ -0,0 +1,4 @@ +Uncaught NewException, code: 1 +Message: Catch me once +Uncaught Exception, code: 2 +Message: Catch me twice