author | Jens Alfke <jens@mooseyard.com> |
Wed May 07 16:47:44 2008 -0700 (2008-05-07) | |
changeset 8 | 5588347dfcbd |
child 11 | e5976864dfe9 |
permissions | -rw-r--r-- |
jens@0 | 1 |
// |
jens@0 | 2 |
// With.m |
jens@0 | 3 |
// MYUtilities |
jens@0 | 4 |
// |
jens@0 | 5 |
// Copyright 2008 Jens Alfke. All rights reserved. |
jens@0 | 6 |
// |
jens@0 | 7 |
|
jens@0 | 8 |
#import "With.h" |
jens@0 | 9 |
#import "Logging.h" |
jens@0 | 10 |
|
jens@0 | 11 |
|
jens@0 | 12 |
@interface NSObject (With) |
jens@0 | 13 |
- (BOOL) endWith: (NSException*)x; |
jens@0 | 14 |
@end |
jens@0 | 15 |
|
jens@0 | 16 |
|
jens@0 | 17 |
void _catchWith( id with, NSException *x ) |
jens@0 | 18 |
{ |
jens@0 | 19 |
Warn(@"Exception thrown from WITH(%@) block: %@",[with class],x); |
jens@0 | 20 |
if( [with respondsToSelector: @selector(endWith:)] ) { |
jens@0 | 21 |
if( ! [with endWith: x] ) |
jens@0 | 22 |
@throw x; // propagate the exception if -endWith: returns NO |
jens@0 | 23 |
} else { |
jens@0 | 24 |
[with endWith]; |
jens@0 | 25 |
} |
jens@0 | 26 |
} |
jens@0 | 27 |
|
jens@0 | 28 |
|
jens@0 | 29 |
|
jens@0 | 30 |
@implementation NSAutoreleasePool (With) |
jens@0 | 31 |
+ (NSAutoreleasePool*) beginWith {return [self new];} |
jens@0 | 32 |
- (void) endWith {[self drain];} |
jens@0 | 33 |
- (BOOL) endWith: (NSException*)x {[self drain]; return YES;} |
jens@0 | 34 |
@end |