Simple Exception Handling, revelation
Simple Exception Handling, revelation
- Subject: Simple Exception Handling, revelation
- From: "Frederick C. Lee" <email@hidden>
- Date: Fri, 19 Apr 2002 14:44:19 -0700
Here's my previous message:
- (double)ComputeResult :(long)sourceValue :(NSString *)sUnit :(NSString
*)tUnit {
NS_DURING {
// Process Data Here.
}
NS_HANDLER {
NSRunAlertPanel(@"Error Panel", @"%@", @"OK", nil, nil,
localException);
}
NS_ENDHANDLER;
return(0);
} // end ComputeResult
What I get is the following:
2002-04-18 16:25:40.278 Converter[798] *** Exception handlers were not
properly removed. Some code has jumped or returned out of an
NS_DURING...NS_HANDLER region without using the NS_VOIDRETURN or
NS_VALUERETURN macros.
Revelation & Solution:
1) Apparently I had manually raised an Exception OUTSIDE of the Block.
This has been fixed:
NS_DURING
[myException raise]; <-- this was above the declaration.
--- My guess is that doing so, I raised myException to the SYSTEM level
which apparently required a way to properly 'remove a handler'; versus
handling within my own Exception Block had it been raised within that
block.
2) I didn't RETAIN the 'myException' object within the init procedure:
- (id)init {
if (self = [super init]) {
[self LoadOnes];
[self LoadFactors];
myException = [NSException
exceptionWithName:@"FileNotFoundException"
reason:@"File Not Found on System"
userInfo:nil];
[myException retain]; <-- THIS WAS MISSING.
}
return self;
}
3) I removed the brackets '{}' and semi-colon ';' which are not needed
in the Exception block.
Ric.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.