Add TextWriter, IOException, per-VM module data and pre-load imports; Add console module with Console class

This commit is contained in:
2026-11-23 18:36:46 +01:00
parent 2243557bf5
commit 4d06edd045
55 changed files with 1679 additions and 675 deletions
+6 -5
View File
@@ -1,7 +1,8 @@
import 'console';
class ExceptionHandler {
public static void printException(Exception $e) {
print('Uncaught ' + get_class($e) + ', code: ' + $e->getCode() + "\nMessage: " + htmlentities($e->getMessage()) + "\n");
Console::Print('Uncaught ' + get_class($e) + ', code: ' + $e->getCode() + "\nMessage: " + htmlentities($e->getMessage()) + "\n");
}
public static void handleException(Exception $e) {
@@ -21,21 +22,21 @@ class Program {
};
set_exception_handler($handler);
try {
print("Called try block 0\n");
Console::Print("Called try block 0\n");
} finally {
print("Called finally block 0\n");
Console::Print("Called finally block 0\n");
}
try {
throw new NewException("Catch me once", 1);
} catch(Exception $e) {
ExceptionHandler::handleException($e);
} finally {
print("Called finally block 1\n");
Console::Print("Called finally block 1\n");
}
try {
throw new NewException("Catch me twice", 2);
} finally {
print("Called finally block 2\n");
Console::Print("Called finally block 2\n");
}
throw new Exception("Catch me thrice", 3);
}