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