From 13c8a8e6c4595686ee3ce7d6cd0be6b4838e0dba Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sun, 6 Jul 2008 16:38:17 +0200 Subject: Make the REPL not segfault upon errors when loading init.lisp. --- MLKReadEvalPrintLoop.m | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'MLKReadEvalPrintLoop.m') diff --git a/MLKReadEvalPrintLoop.m b/MLKReadEvalPrintLoop.m index 8c06496..1005ac7 100644 --- a/MLKReadEvalPrintLoop.m +++ b/MLKReadEvalPrintLoop.m @@ -80,13 +80,23 @@ static const char *prompt (EditLine *e) { el_set (editline, EL_HIST, history, commands); printf ("Loading init.lisp.\n"); - input = [NSInputStream inputStreamWithFileAtPath:@"init.lisp"]; - stream = AUTORELEASE ([[MLKStream alloc] initWithInputStream:input]); + NS_DURING + { + input = [NSInputStream inputStreamWithFileAtPath:@"init.lisp"]; + stream = AUTORELEASE ([[MLKStream alloc] initWithInputStream:input]); - [input open]; - [MLKInterpreter load:stream verbose:YES print:YES]; - success = [MLKInterpreter load:stream verbose:YES print:YES]; - [input close]; + [input open]; + [MLKInterpreter load:stream verbose:YES print:YES]; + success = [MLKInterpreter load:stream verbose:YES print:YES]; + [input close]; + } + NS_HANDLER + { + printf ("Caught an unhandled exception.\nName: %s\nReason: %s\n", + [[localException name] UTF8String], + [[localException reason] UTF8String]); + } + NS_ENDHANDLER; printf ("Done.\n\n"); -- cgit v1.2.3