1
/** Implementation for NSError for GNUStep
2
Copyright (C) 2004 Free Software Foundation, Inc.
4
Written by: Richard Frith-Macdonald <rfm@gnu.org>
7
This file is part of the GNUstep Base Library.
9
This library is free software; you can redistribute it and/or
10
modify it under the terms of the GNU Library General Public
11
License as published by the Free Software Foundation; either
12
version 2 of the License, or (at your option) any later version.
14
This library is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
Library General Public License for more details.
19
You should have received a copy of the GNU Library General Public
20
License along with this library; if not, write to the Free
21
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
24
#include <Foundation/NSDictionary.h>
25
#include <Foundation/NSString.h>
26
#include <Foundation/NSError.h>
27
#include <Foundation/NSCoder.h>
29
NSString* const NSLocalizedDescriptionKey = @"NSLocalizedDescriptionKey";
30
NSString* const NSUnderlyingErrorKey = @"NSUnderlyingErrorKey";
31
NSString* const NSMACHErrorDomain = @"NSMACHErrorDomain";
32
NSString* const NSOSStatusErrorDomain = @"NSOSStatusErrorDomain";
33
NSString* const NSPOSIXErrorDomain = @"NSPOSIXErrorDomain";
35
@implementation NSError
37
+ (id) errorWithDomain: (NSString*)aDomain
39
userInfo: (NSDictionary*)aDictionary
41
NSError *e = [self allocWithZone: NSDefaultMallocZone()];
43
e = [e initWithDomain: aDomain code: aCode userInfo: aDictionary];
44
return AUTORELEASE(e);
52
- (id) copyWithZone: (NSZone*)z
54
NSError *e = [[self class] allocWithZone: z];
56
e = [e initWithDomain: _domain code: _code userInfo: _userInfo];
72
- (void) encodeWithCoder: (NSCoder*)aCoder
74
if ([aCoder allowsKeyedCoding])
76
[aCoder encodeInt: _code forKey: @"NSCode"];
77
[aCoder encodeObject: _domain forKey: @"NSDomain"];
78
[aCoder encodeObject: _userInfo forKey: @"NSUserInfo"];
82
[aCoder encodeValueOfObjCType: @encode(int) at: &_code];
83
[aCoder encodeValueOfObjCType: @encode(id) at: &_domain];
84
[aCoder encodeValueOfObjCType: @encode(id) at: &_userInfo];
90
return [self initWithDomain: nil code: 0 userInfo: nil];
93
- (id) initWithCoder: (NSCoder*)aCoder
95
if ([aCoder allowsKeyedCoding])
101
c = [aCoder decodeIntForKey: @"NSCode"];
102
d = [aCoder decodeObjectForKey: @"NSDomain"];
103
u = [aCoder decodeObjectForKey: @"NSUserInfo"];
104
self = [self initWithDomain: d code: c userInfo: u];
108
[aCoder decodeValueOfObjCType: @encode(int) at: &_code];
109
[aCoder decodeValueOfObjCType: @encode(id) at: &_domain];
110
[aCoder decodeValueOfObjCType: @encode(id) at: &_userInfo];
115
- (id) initWithDomain: (NSString*)aDomain
117
userInfo: (NSDictionary*)aDictionary
121
NSLog(@"[%@-%@] with nil domain",
122
NSStringFromClass([self class]), NSStringFromSelector(_cmd));
125
else if ((self = [super init]) != nil)
127
ASSIGN(_domain, aDomain);
129
ASSIGN(_userInfo, aDictionary);
134
- (NSString *)localizedDescription
136
NSString *desc = [_userInfo objectForKey: NSLocalizedDescriptionKey];
140
desc = [NSString stringWithFormat: @"%@ %d", _domain, _code];
145
- (NSDictionary*) userInfo