API  0.9.7
 All Classes Files Functions Variables Macros Groups Pages
CPError.j
Go to the documentation of this file.
1 /*
2  * CPError.j
3  * Foundation
4  *
5  * Created by Alexander Ljungberg.
6  * Copyright 2013, SlevenBits Ltd.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 
24 CPCappuccinoErrorDomain = CPCocoaErrorDomain = @"CPCappuccinoErrorDomain";
25 // CPPOSIXErrorDomain = @"CPPOSIXErrorDomain";
26 // CPOSStatusErrorDomain = @"CPOSStatusErrorDomain";
27 
28 CPUnderlyingErrorKey = @"CPUnderlyingErrorKey";
29 
30 CPLocalizedDescriptionKey = @"CPLocalizedDescriptionKey";
31 CPLocalizedFailureReasonErrorKey = @"CPLocalizedFailureReasonErrorKey";
32 CPLocalizedRecoverySuggestionErrorKey = @"CPLocalizedRecoverySuggestionErrorKey";
33 CPLocalizedRecoveryOptionsErrorKey = @"CPLocalizedRecoveryOptionsErrorKey";
34 CPRecoveryAttempterErrorKey = @"CPRecoveryAttempterErrorKey";
35 CPHelpAnchorErrorKey = @"CPHelpAnchorErrorKey";
36 
37 CPStringEncodingErrorKey = @"CPStringEncodingErrorKey";
38 CPURLErrorKey = @"CPURLErrorKey";
39 CPFilePathErrorKey = @"CPFilePathErrorKey";
40 
41 
42 @implementation CPError : CPObject
43 {
44  CPInteger _code;
45  CPString _domain;
46  CPDictionary _userInfo;
47 }
48 
49 + (id)errorWithDomain:(CPString)aDomain code:(CPInteger)aCode userInfo:(CPDictionary)aDict
50 {
51  return [[CPError alloc] initWithDomain:aDomain code:aCode userInfo:aDict];
52 }
53 
54 - (id)initWithDomain:(CPString)aDomain code:(CPInteger)aCode userInfo:(CPDictionary)aDict
55 {
56  if (self = [super init])
57  {
58  _domain = aDomain;
59  _code = aCode;
60  _userInfo = aDict;
61  }
62 
63  return self;
64 }
65 
66 - (CPString)localizedDescription
67 {
68  return [_userInfo objectForKey:CPLocalizedDescriptionKey];
69 }
70 
71 - (CPString)localizedFailureReason
72 {
73  return [_userInfo objectForKey:CPLocalizedFailureReasonErrorKey];
74 }
75 
76 - (CPArray)localizedRecoveryOptions
77 {
78  return [_userInfo objectForKey:CPLocalizedRecoveryOptionsErrorKey];
79 }
80 
81 - (CPString)localizedRecoverySuggestion
82 {
83  return [_userInfo objectForKey:CPLocalizedRecoverySuggestionErrorKey];
84 }
85 
86 - (id)recoveryAttempter
87 {
88  return [_userInfo objectForKey:CPRecoveryAttempterErrorKey];
89 }
90 
91 - (CPString)description
92 {
93  return [CPString stringWithFormat:@"Error Domain=%@ Code=%d UserInfo=%p %@", _domain, _code, _userInfo, [self localizedDescription]];
94 }
95 
96 @end
97 
99 
103 - (CPInteger)code
104 {
105  return _code;
106 }
107 
111 - (CPString)domain
112 {
113  return _domain;
114 }
115 
119 - (CPDictionary)userInfo
120 {
121  return _userInfo;
122 }
123 
124 @end