Aer Interpreter Source
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
949 B

  1. class ExceptionHandler {
  2. public static void printException(Exception $e) {
  3. print('Uncaught ' + get_class($e) + ', code: ' + $e->getCode() + "\nMessage: " + htmlentities($e->getMessage()) + "\n");
  4. }
  5. public static void handleException(Exception $e) {
  6. ExceptionHandler::printException($e);
  7. }
  8. }
  9. class NewException extends Exception {
  10. }
  11. class Program {
  12. public void main() {
  13. callback $handler = void(Exception $e) {
  14. ExceptionHandler::handleException($e);
  15. };
  16. set_exception_handler($handler);
  17. try {
  18. print("Called try block 0\n");
  19. } finally {
  20. print("Called finally block 0\n");
  21. }
  22. try {
  23. throw new NewException("Catch me once", 1);
  24. } catch(Exception $e) {
  25. ExceptionHandler::handleException($e);
  26. } finally {
  27. print("Called finally block 1\n");
  28. }
  29. try {
  30. throw new NewException("Catch me twice", 2);
  31. } finally {
  32. print("Called finally block 2\n");
  33. }
  34. throw new Exception("Catch me thrice", 3);
  35. }
  36. }