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