Let's test exceptions.
The build was successful. Details

This commit is contained in:
Rafal Kupiec 2019-04-10 18:59:26 +02:00
parent 2a4e47e782
commit 08307c5ad6
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
2 changed files with 37 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -0,0 +1,4 @@
Uncaught NewException, code: 1
Message: Catch me once
Uncaught Exception, code: 2
Message: Catch me twice