Artifact 6d13800ff5c4f66f714a614d18d271531e8c816feb9c425103f3946506dcdd64:
- File
src/OFExceptions.m
— part of check-in
[b597d49f43]
at
2008-10-08 23:15:26
on branch trunk
— Multiple changes, see details.
* OFObject getMem: renamd to getMemWithSize:.
* OFString compare: renamed to compareTo:.
* Exceptions don't throw itself anymore.
* Exceptions include an error string now.
* Exceptions now got raise and string.
* New methods for OFFile:
* changeModeOfFile:toMode:
* changeOwnerOfFile:toOwner:andGroup:
* delete:
* link:to:
* symlink:to:
* OFFile isEndOfFile renamd to atEndOfFile
* OFNotImplementedExeception newWithObject:andMethod renamed to
newWithObject:andSelector:.
* Tests updated accordingly.
* TODO list added. (user: js, size: 3769) [annotate] [blame] [check-ins using]
/* * Copyright (c) 2008 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #import <stdio.h> #import <stdlib.h> #import "OFExceptions.h" @implementation OFException + newWithObject: (id)obj { return [[OFException alloc] initWithObject: obj]; } - initWithObject: (id)obj { if ((self = [super init])) errstr = NULL; return self; } - free { if (errstr != NULL) free(errstr); return [super free]; } - (void)raise { @throw self; } - (char*)string { return errstr; } @end @implementation OFNoMemException + newWithObject: (id)obj andSize: (size_t)size { return [[OFNoMemException alloc] initWithObject: obj andSize: size]; } - initWithObject: (id)obj andSize: (size_t)size { if ((self = [super init])) asprintf(&errstr, "ERROR: Could not allocate %zu bytes for " "object of class %s!\n", size, [obj name]); return self; } @end @implementation OFNotImplementedException + newWithObject: (id)obj andSelector: (SEL)sel { return [[OFNotImplementedException alloc] initWithObject: obj andSelector: sel]; } - initWithObject: (id)obj andSelector: (SEL)sel { if ((self = [super init])) /* FIXME: Is casting SEL to char* portable? */ asprintf(&errstr, "ERROR: Requested selector %s not " "implemented in %s!\n", (char*)sel, [obj name]); return self; } @end @implementation OFMemNotPartOfObjException + newWithObject: (id)obj andPointer: (void*)ptr { return [[OFMemNotPartOfObjException alloc] initWithObject: obj andPointer: ptr]; } - initWithObject: (id)obj andPointer: (void*)ptr { if ((self = [super init])) asprintf(&errstr, "ERROR: Memory at %p was not allocated as " "part of object of class\n" "ERROR: %s!\n" "ERROR: -> Not changing memory allocation!\n" "ERROR: (Hint: It is possible that you tried to free the " "same memory twice!)\n", ptr, [obj name]); return self; } @end @implementation OFOverflowException + newWithObject: (id)obj { return [[OFOverflowException alloc] initWithObject: obj]; } - initWithObject: (id)obj { if ((self = [super init])) asprintf(&errstr, "ERROR: Overflow in object of class %s!\n", [obj name]); return self; } @end @implementation OFOpenFileFailedException + newWithObject: (id)obj andPath: (const char*)path andMode: (const char*)mode { return [[OFOpenFileFailedException alloc] initWithObject: obj andPath: path andMode: mode]; } - initWithObject: (id)obj andPath: (const char*)path andMode: (const char*)mode { if ((self = [super init])) asprintf(&errstr, "ERROR: Failed to open file %s with mode %s " "in object of class %s!\n", path, mode, [self name]); return self; } @end @implementation OFReadOrWriteFailedException + newWithObject: (id)obj andSize: (size_t)size andNItems: (size_t)nitems { return [[OFReadOrWriteFailedException alloc] initWithObject: obj andSize: size andNItems: nitems]; } @end @implementation OFReadFailedException - initWithObject: (id)obj andSize: (size_t)size andNItems: (size_t)nitems { if ((self = [super init])) asprintf(&errstr, "ERROR: Failed to read %zu items of size " "%zu in object of class %s!\n", nitems, size, [obj name]); return self; } @end @implementation OFWriteFailedException - initWithObject: (id)obj andSize: (size_t)size andNItems: (size_t)nitems { if ((self = [super init])) asprintf(&errstr, "ERROR: Failed to write %zu items of size " "%zu in object of class %s!\n", nitems, size, [obj name]); return self; } @end