snej@22: // snej@22: // MYErrorUtils.h snej@22: // MYCrypto snej@22: // snej@22: // Created by Jens Alfke on 2/25/09. snej@22: // Copyright 2009 Jens Alfke. All rights reserved. snej@22: // snej@22: snej@22: #import snej@22: @class NSError, NSString; snej@22: snej@22: snej@22: extern NSString* const MYErrorDomain; snej@22: snej@22: enum { snej@22: /** "Miscellaneous" error code, set by MYMiscError. snej@22: Handy during development, but before shipping you really should define snej@22: individual error codes for each error condition. */ snej@22: kMYErrorMisc = 999999, snej@22: }; snej@22: snej@22: snej@22: /** Creates an NSError in MYErrorDomain. */ snej@22: NSError *MYError( int errorCode, NSString *domain, NSString *messageFormat, ... ) snej@22: __attribute__ ((format (__NSString__, 3, 4))); snej@22: snej@23: /** A variant of MYError, useful for returning from a method. snej@23: If errorCode is nonzero, constructs an NSError and stores it into *outError, snej@23: then returns NO. Otherwise returns YES. */ snej@23: BOOL MYReturnError( NSError **outError, snej@23: int errorCode, NSString *domain, NSString *messageFormat, ... ) snej@23: __attribute__ ((format (__NSString__, 4, 5))); snej@23: snej@22: /** Convenience function for creating NSErrors. snej@22: Stores an NSError into *error, and returns NO. snej@22: Domain will be MYErrorDomain, code will be kMYErrorMisc. snej@22: Handy during development, but before shipping you really should define snej@22: individual error codes for each error condition. */ snej@22: BOOL MYMiscError( NSError **outError, NSString *messageFormat, ... ) snej@22: __attribute__ ((format (__NSString__, 2, 3))); snej@22: snej@22: NSString* MYPrintableErrorCode( int code ); snej@22: NSString* MYErrorName( NSString *domain, int code ); snej@22: snej@22: @interface NSError (MYUtilities) snej@22: /** Prepends a message to the beginning of the receiver's existing message, snej@22: and returns the modified NSError. */ snej@22: - (NSError*) my_errorByPrependingMessage: (NSString*)message; snej@22: snej@22: - (NSString*) my_nameOfCode; snej@22: snej@22: @end