diff -r 000000000000 -r 59addced5e2a With.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/With.m Fri May 02 12:49:43 2008 -0700 @@ -0,0 +1,34 @@ +// +// With.m +// MYUtilities +// +// Copyright 2008 Jens Alfke. All rights reserved. +// + +#import "With.h" +#import "Logging.h" + + +@interface NSObject (With) +- (BOOL) endWith: (NSException*)x; +@end + + +void _catchWith( id with, NSException *x ) +{ + Warn(@"Exception thrown from WITH(%@) block: %@",[with class],x); + if( [with respondsToSelector: @selector(endWith:)] ) { + if( ! [with endWith: x] ) + @throw x; // propagate the exception if -endWith: returns NO + } else { + [with endWith]; + } +} + + + +@implementation NSAutoreleasePool (With) ++ (NSAutoreleasePool*) beginWith {return [self new];} +- (void) endWith {[self drain];} +- (BOOL) endWith: (NSException*)x {[self drain]; return YES;} +@end \ No newline at end of file