MYErrorUtils.h
author Jens Alfke <jens@mooseyard.com>
Wed Sep 02 08:41:25 2009 -0700 (2009-09-02)
changeset 35 5cab3034d3a1
parent 22 a9da6c5d3f7c
permissions -rw-r--r--
10.6 compatibility: Fix some new compiler warnings, and work around apparent regressions in NSTask and -stringByStandardizingPath.
     1 //
     2 //  MYErrorUtils.h
     3 //  MYCrypto
     4 //
     5 //  Created by Jens Alfke on 2/25/09.
     6 //  Copyright 2009 Jens Alfke. All rights reserved.
     7 //
     8 
     9 #import <Foundation/NSObject.h>
    10 @class NSError, NSString;
    11 
    12 
    13 extern NSString* const MYErrorDomain;
    14 
    15 enum {
    16     /** "Miscellaneous" error code, set by MYMiscError.
    17         Handy during development, but before shipping you really should define
    18         individual error codes for each error condition. */
    19     kMYErrorMisc = 999999,
    20 };
    21 
    22 
    23 /** Creates an NSError in MYErrorDomain. */
    24 NSError *MYError( int errorCode, NSString *domain, NSString *messageFormat, ... ) 
    25                                 __attribute__ ((format (__NSString__, 3, 4)));
    26 
    27 /** A variant of MYError, useful for returning from a method.
    28     If errorCode is nonzero, constructs an NSError and stores it into *outError,
    29     then returns NO. Otherwise returns YES. */
    30 BOOL MYReturnError( NSError **outError,
    31                     int errorCode, NSString *domain, NSString *messageFormat, ... ) 
    32                                 __attribute__ ((format (__NSString__, 4, 5)));
    33 
    34 /** Convenience function for creating NSErrors.
    35     Stores an NSError into *error, and returns NO.
    36     Domain will be MYErrorDomain, code will be kMYErrorMisc.
    37     Handy during development, but before shipping you really should define
    38     individual error codes for each error condition. */
    39 BOOL MYMiscError( NSError **outError, NSString *messageFormat, ... )
    40                                 __attribute__ ((format (__NSString__, 2, 3)));
    41 
    42 NSString* MYPrintableErrorCode( int code );
    43 NSString* MYErrorName( NSString *domain, int code );
    44 
    45 @interface NSError (MYUtilities)
    46 /** Prepends a message to the beginning of the receiver's existing message,
    47     and returns the modified NSError. */
    48 - (NSError*) my_errorByPrependingMessage: (NSString*)message;
    49 
    50 - (NSString*) my_nameOfCode;
    51 
    52 @end