/* Exception.m -*-objc-*- * * Copyright Niels Möller 1995 * * Freely distributable under the terms and conditions of the * GNU General Public License. */ #include #include #include #include #define CANT_HAPPEN assert(0) #define FRAME_STACK StackFrame @implementation Exception - (void) raise { frame_id frame; id catch; frame = [FRAME_STACK findFrameMatching: self]; if (frame) { catch = ( (struct frstack_catch_object_frame *) frame)->object; [catch exception: self]; [FRAME_STACK unwind: frame pleaseReturn: NO]; CANT_HAPPEN; } [self noHandler]; } - (BOOL) ofExceptionType: (exception_type) type { return [self conformsTo: type]; } - (const char *) message { /* Default message is name of class */ return [self name]; } - (void) noHandler { return; } - (void) finished { [self free]; } @end /* Exception */ @implementation Error - (void) noHandler { /* No handler for this error. Exit program. */ [self error: "No catcher for error: %s.\n", [self message]]; } @end /* Error */ @implementation SimpleError #if 0 + newError: (const char *) msg { id me = [super new]; return [ [ [me message: msg] constantMessage: NO] constant: NO]; } + newErrorConstantMessage: (const char *) message { id me = [super new]; return [ [ [me message: message] constantMessage: YES] constant: NO]; } + newConstantError: (const char *) message { id me = [super new]; return [ [ [me message: message] constantMessage: YES] constant: YES]; } #endif - message: (const char *) msg { message = msg; return self; } - constantMessage: (BOOL) flag { constantMessage = flag; return self; } - constant: (BOOL) flag { constantObject = flag; return self; } - (void) finished { if (!constantObject) [self free]; } - free { if (!constantMessage) free((char *)message); return [super free]; } @end /* SimpleError */ @implementation OutOfMemory + newMessage: (const char *) msg { id me = [super new]; [me message: msg]; [me constantMessage: YES]; [me constant: YES]; return me; } @end /* OutOfMemory */ @implementation ThrowWithoutCatch - value { return value; } - value: newValue { value = newValue; return self; } - tag { return tag; } - tag: newTag { tag = newTag; return self;} - (const char *) message { return "a throw was attempted, without a matching catch"; } @end /* ThrowWithoutCatch */