/* Error.m * * Copyright Niels Möller 1995 * * Freely distributable under the terms and conditions of the * GNU General Public License. */ #include #include #include /* I'm not sure if I should hardcode StackFrame here or not. */ #ifndef FRAME_STACK #define FRAME_STACK StackFrame #endif FRAME_STACK #if 0 static int cmp_kindof(frame_id f, void *data) { return (f->type == frstack_catch_object) && [ (id) data isKindOf: ( (struct frstack_catch_object_frame *) f)->object]; } #endif @implementation Error - raise { frame_id frame; id catch; frame = [FRAME_STACK findFrameMatching: self]; [FRAME_STACK unwind: frame]; if (frame) { catch = ( (struct frstack_catch_object_frame *) frame)->object; [catch setError: self]; longjmp([catch where]->jmp, 19); /* Never returns here */ } /* No handler for this error. Exit program. */ return [self error: "No catcher for %s: %s.", [self name], [self message]]; } - (const char *) message { return "Error"; } @end /* Error*/ @implementation ErrorNoMemory : Error - message: (char *) descr freeIt: (BOOL) freeFlag { message = descr; freeMessage = freeFlag; return self; } - free { if (freeMessage) free(message); return [super free]; } @end /* ErrorNoMemory */ @implementation ErrorNoCatch - value { return value; } - value: newValue { value = newValue; return self; } - tag { return tag; } - tag: newTag { tag = newTag; return self;} - (const char *) message { return "throw without matching catch"; } @end /* ErrorNoCatch */