From 6684d33bab073d267198ef7159cb627c2ecddc0a Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Tue, 24 Jun 2008 16:17:17 +0200 Subject: Make the read-eval-print loop more robust in the face of exceptions. --- MLKReadEvalPrintLoop.m | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/MLKReadEvalPrintLoop.m b/MLKReadEvalPrintLoop.m index 392b4ed..4ccc339 100644 --- a/MLKReadEvalPrintLoop.m +++ b/MLKReadEvalPrintLoop.m @@ -39,12 +39,23 @@ static char **_argv; static const char *prompt (EditLine *e) { - MLKPackage *package = [[MLKDynamicContext currentContext] - valueForSymbol:[[MLKPackage - findPackage:@"COMMON-LISP"] - intern:@"*PACKAGE*"]]; - - return [[NSString stringWithFormat:@"%@> ", [package name]] UTF8String]; + NS_DURING + { + MLKPackage *package = [[MLKDynamicContext currentContext] + valueForSymbol:[[MLKPackage + findPackage:@"COMMON-LISP"] + intern:@"*PACKAGE*"]]; + + return [[NSString stringWithFormat:@"%@> ", [package name]] UTF8String]; + } + NS_HANDLER + { + printf ("Caught an unhandled exception.\nName: %s\nReason: %s\n", + [[localException name] UTF8String], + [[localException reason] UTF8String]); + return "> "; + } + NS_ENDHANDLER } -- cgit v1.2.3