mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-12 17:11:12 +00:00
Added NSError
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@19360 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
bc0414e6ab
commit
cc7fc40092
6 changed files with 279 additions and 0 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
2004-05-17 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Headers/Foundation/Foundation.h: Add NSError.h
|
||||||
|
* Headers/Foundation/NSError.h: New MacOS-X compatibility header
|
||||||
|
* Source/DocMakefile: Add NSError
|
||||||
|
* Source/GNUmakefile: Add NSError
|
||||||
|
* Source/NSError.m: new MacOS-X compatibility class.
|
||||||
|
|
||||||
2004-05-16 Richard Frith-Macdonald <rfm@gnu.org>
|
2004-05-16 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/Additions/GSXML.m: Corrected value for cdata in sax-like
|
* Source/Additions/GSXML.m: Corrected value for cdata in sax-like
|
||||||
|
|
|
@ -51,6 +51,7 @@
|
||||||
#include <Foundation/NSDistributedLock.h>
|
#include <Foundation/NSDistributedLock.h>
|
||||||
#include <Foundation/NSDistributedNotificationCenter.h>
|
#include <Foundation/NSDistributedNotificationCenter.h>
|
||||||
#include <Foundation/NSEnumerator.h>
|
#include <Foundation/NSEnumerator.h>
|
||||||
|
#include <Foundation/NSError.h>
|
||||||
#include <Foundation/NSException.h>
|
#include <Foundation/NSException.h>
|
||||||
#include <Foundation/NSFileHandle.h>
|
#include <Foundation/NSFileHandle.h>
|
||||||
#include <Foundation/NSFileManager.h>
|
#include <Foundation/NSFileManager.h>
|
||||||
|
|
117
Headers/Foundation/NSError.h
Normal file
117
Headers/Foundation/NSError.h
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
/** Interface for NSError for GNUStep
|
||||||
|
Copyright (C) 2004 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
Written by: Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
Date: May 2004
|
||||||
|
|
||||||
|
This file is part of the GNUstep Base Library.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Library General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Library General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Library General Public
|
||||||
|
License along with this library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||||
|
|
||||||
|
AutogsdocSource: NSError.m
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __NSError_h_GNUSTEP_BASE_INCLUDE
|
||||||
|
#define __NSError_h_GNUSTEP_BASE_INCLUDE
|
||||||
|
|
||||||
|
#ifndef STRICT_OPENSTEP
|
||||||
|
|
||||||
|
#include <Foundation/NSObject.h>
|
||||||
|
|
||||||
|
@class NSDictionary, NSString;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key for user info dictionary component which describes the error in
|
||||||
|
* a human readable format.
|
||||||
|
*/
|
||||||
|
GS_EXPORT NSString* const NSLocalizedDescriptionKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Where one error has caused another, the underlying error can be stored
|
||||||
|
* in the user info dictionary uisng this key.
|
||||||
|
*/
|
||||||
|
GS_EXPORT NSString* const NSUnderlyingErrorKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Domain for system errors (on MACH).
|
||||||
|
*/
|
||||||
|
GS_EXPORT NSString* const NSMACHErrorDomain;
|
||||||
|
/**
|
||||||
|
* Domain for system errors.
|
||||||
|
*/
|
||||||
|
GS_EXPORT NSString* const NSOSStatusErrorDomain;
|
||||||
|
/**
|
||||||
|
* Domain for system and system library errors.
|
||||||
|
*/
|
||||||
|
GS_EXPORT NSString* const NSPOSIXErrorDomain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error information class
|
||||||
|
*/
|
||||||
|
@interface NSError : NSObject <NSCopying, NSCoding>
|
||||||
|
{
|
||||||
|
@private
|
||||||
|
int _code;
|
||||||
|
NSString *_domain;
|
||||||
|
NSDictionary *_userInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates and returns an autoreleased NSError instance by calling
|
||||||
|
* -initWithDomain:code:userInfo:
|
||||||
|
*/
|
||||||
|
+ (id) errorWithDomain: (NSString*)aDomain
|
||||||
|
code: (int)aCode
|
||||||
|
userInfo: (NSDictionary*)aDictionary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the error code ... which is not globally unique, just unique for
|
||||||
|
* a particular domain.
|
||||||
|
*/
|
||||||
|
- (int) code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the domain for this instance.
|
||||||
|
*/
|
||||||
|
- (NSString*) domain;
|
||||||
|
|
||||||
|
/** <init />
|
||||||
|
* Initialises the receiver using the supplied domain, code, and info.<br />
|
||||||
|
* The domain musat be non-nil.
|
||||||
|
*/
|
||||||
|
- (id) initWithDomain: (NSString*)aDomain
|
||||||
|
code: (int)aCode
|
||||||
|
userInfo: (NSDictionary*)aDictionary;
|
||||||
|
|
||||||
|
/** <override-subclass />
|
||||||
|
* Return a human readable description for the error.<br />
|
||||||
|
* The default implementation uses the value from the user info dictionary
|
||||||
|
* if it is available, otherwise it generates a generic one from domain
|
||||||
|
* and code.
|
||||||
|
*/
|
||||||
|
- (NSString *)localizedDescription;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the user info for this instance (or nil if none is set)<br />
|
||||||
|
* The NSLocalizedDescriptionKey should locate a human readable description
|
||||||
|
* in the dictionary.<br />
|
||||||
|
* The NSUnderlyingErrorKey key should locate an NSError instance if an
|
||||||
|
* error is available describing any underlying problem.<br />
|
||||||
|
*/
|
||||||
|
- (NSDictionary*) userInfo;
|
||||||
|
@end
|
||||||
|
|
||||||
|
#endif /* STRICT_OPENSTEP */
|
||||||
|
#endif /* __NSError_h_GNUSTEP_BASE_INCLUDE*/
|
|
@ -55,6 +55,7 @@ NSDistantObject.h \
|
||||||
NSDistributedLock.h \
|
NSDistributedLock.h \
|
||||||
NSDistributedNotificationCenter.h \
|
NSDistributedNotificationCenter.h \
|
||||||
NSEnumerator.h \
|
NSEnumerator.h \
|
||||||
|
NSError.h \
|
||||||
NSException.h \
|
NSException.h \
|
||||||
NSFileHandle.h \
|
NSFileHandle.h \
|
||||||
NSFileManager.h \
|
NSFileManager.h \
|
||||||
|
|
|
@ -166,6 +166,7 @@ NSDistantObject.m \
|
||||||
NSDistributedLock.m \
|
NSDistributedLock.m \
|
||||||
NSDistributedNotificationCenter.m \
|
NSDistributedNotificationCenter.m \
|
||||||
NSEnumerator.m \
|
NSEnumerator.m \
|
||||||
|
NSError.m \
|
||||||
NSException.m \
|
NSException.m \
|
||||||
NSFileHandle.m \
|
NSFileHandle.m \
|
||||||
NSFileManager.m \
|
NSFileManager.m \
|
||||||
|
@ -283,6 +284,7 @@ NSDistantObject.h \
|
||||||
NSDistributedLock.h \
|
NSDistributedLock.h \
|
||||||
NSDistributedNotificationCenter.h \
|
NSDistributedNotificationCenter.h \
|
||||||
NSEnumerator.h \
|
NSEnumerator.h \
|
||||||
|
NSError.h \
|
||||||
NSException.h \
|
NSException.h \
|
||||||
NSFileHandle.h \
|
NSFileHandle.h \
|
||||||
NSFileManager.h \
|
NSFileManager.h \
|
||||||
|
|
150
Source/NSError.m
Normal file
150
Source/NSError.m
Normal file
|
@ -0,0 +1,150 @@
|
||||||
|
/** Implementation for NSError for GNUStep
|
||||||
|
Copyright (C) 2004 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
Written by: Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
Date: May 2004
|
||||||
|
|
||||||
|
This file is part of the GNUstep Base Library.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Library General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Library General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Library General Public
|
||||||
|
License along with this library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Foundation/NSDictionary.h>
|
||||||
|
#include <Foundation/NSString.h>
|
||||||
|
#include <Foundation/NSError.h>
|
||||||
|
#include <Foundation/NSCoder.h>
|
||||||
|
|
||||||
|
NSString* const NSLocalizedDescriptionKey = @"NSLocalizedDescriptionKey";
|
||||||
|
NSString* const NSUnderlyingErrorKey = @"NSUnderlyingErrorKey";
|
||||||
|
NSString* const NSMACHErrorDomain = @"NSMACHErrorDomain";
|
||||||
|
NSString* const NSOSStatusErrorDomain = @"NSOSStatusErrorDomain";
|
||||||
|
NSString* const NSPOSIXErrorDomain = @"NSPOSIXErrorDomain";
|
||||||
|
|
||||||
|
@implementation NSError
|
||||||
|
|
||||||
|
+ (id) errorWithDomain: (NSString*)aDomain
|
||||||
|
code: (int)aCode
|
||||||
|
userInfo: (NSDictionary*)aDictionary
|
||||||
|
{
|
||||||
|
NSError *e = [self allocWithZone: NSDefaultMallocZone()];
|
||||||
|
|
||||||
|
e = [e initWithDomain: aDomain code: aCode userInfo: aDictionary];
|
||||||
|
return AUTORELEASE(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (int) code
|
||||||
|
{
|
||||||
|
return _code;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id) copyWithZone: (NSZone*)z
|
||||||
|
{
|
||||||
|
NSError *e = [[self class] allocWithZone: z];
|
||||||
|
|
||||||
|
e = [e initWithDomain: _domain code: _code userInfo: _userInfo];
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) dealloc
|
||||||
|
{
|
||||||
|
DESTROY(_domain);
|
||||||
|
DESTROY(_userInfo);
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString*) domain
|
||||||
|
{
|
||||||
|
return _domain;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||||
|
{
|
||||||
|
if ([aCoder allowsKeyedCoding])
|
||||||
|
{
|
||||||
|
[aCoder encodeInt: _code forKey: @"NSCode"];
|
||||||
|
[aCoder encodeObject: _domain forKey: @"NSDomain"];
|
||||||
|
[aCoder encodeObject: _userInfo forKey: @"NSUserInfo"];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[aCoder encodeValueOfObjCType: @encode(int) at: &_code];
|
||||||
|
[aCoder encodeValueOfObjCType: @encode(id) at: &_domain];
|
||||||
|
[aCoder encodeValueOfObjCType: @encode(id) at: &_userInfo];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id) init
|
||||||
|
{
|
||||||
|
return [self initWithDomain: nil code: 0 userInfo: nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id) initWithCoder: (NSCoder*)aCoder
|
||||||
|
{
|
||||||
|
if ([aCoder allowsKeyedCoding])
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
id d;
|
||||||
|
id u;
|
||||||
|
|
||||||
|
c = [aCoder decodeIntForKey: @"NSCode"];
|
||||||
|
d = [aCoder decodeObjectForKey: @"NSDomain"];
|
||||||
|
u = [aCoder decodeObjectForKey: @"NSUserInfo"];
|
||||||
|
self = [self initWithDomain: d code: c userInfo: u];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[aCoder decodeValueOfObjCType: @encode(int) at: &_code];
|
||||||
|
[aCoder decodeValueOfObjCType: @encode(id) at: &_domain];
|
||||||
|
[aCoder decodeValueOfObjCType: @encode(id) at: &_userInfo];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id) initWithDomain: (NSString*)aDomain
|
||||||
|
code: (int)aCode
|
||||||
|
userInfo: (NSDictionary*)aDictionary
|
||||||
|
{
|
||||||
|
if (aDomain == nil)
|
||||||
|
{
|
||||||
|
NSLog(@"[%@-%@] with nil domain",
|
||||||
|
NSStringFromClass([self class]), NSStringFromSelector(_cmd));
|
||||||
|
DESTROY(self);
|
||||||
|
}
|
||||||
|
else if ((self = [super init]) != nil)
|
||||||
|
{
|
||||||
|
ASSIGN(_domain, aDomain);
|
||||||
|
_code = aCode;
|
||||||
|
ASSIGN(_userInfo, aDictionary);
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString *)localizedDescription
|
||||||
|
{
|
||||||
|
NSString *desc = [_userInfo objectForKey: NSLocalizedDescriptionKey];
|
||||||
|
|
||||||
|
if (desc == nil)
|
||||||
|
{
|
||||||
|
desc = [NSString stringWithFormat: @"%@ %d", _domain, _code];
|
||||||
|
}
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSDictionary*) userInfo
|
||||||
|
{
|
||||||
|
return _userInfo;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
Loading…
Reference in a new issue