@@ -18,12 +18,13 @@ return [[OFException alloc] initWithObject: obj]; } - initWithObject: (id)obj { + self = [super init]; @throw self; - return [super init]; + return self; } @end @implementation OFNoMemException + newWithObject: (id)obj @@ -37,12 +38,13 @@ andSize: (size_t)size { fprintf(stderr, "ERROR: Could not allocate %zu bytes for object %s!\n", size, [obj name]); + self = [super init]; @throw self; - return [super init]; + return self; } @end @implementation OFNotImplementedException + newWithObject: (id)obj @@ -56,12 +58,13 @@ andMethod: (const char*)method { fprintf(stderr, "ERROR: Requested method %s not implemented in %s!\n", method, [obj name]); + self = [super init]; @throw self; - return [super init]; + return self; } @end @implementation OFMemNotPartOfObjException + newWithObject: (id)obj @@ -78,12 +81,13 @@ "object %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]); + self = [super init]; @throw self; - return [super init]; + return self; } @end @implementation OFOverflowException + newWithObject: (id)obj @@ -93,31 +97,72 @@ - initWithObject: (id)obj { fprintf(stderr, "ERROR: Overflow in object %s!\n", [obj name]); + self = [super init]; + @throw self; + 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 +{ + fprintf(stderr, "ERROR: Failed to open file %s with mode %s in " + "object %s!\n", path, mode, [self name]); + + self = [super init]; @throw self; - return [super init]; + return self; } @end -@implementation OFReadFailedException +@implementation OFReadOrWriteFailedException + newWithObject: (id)obj andSize: (size_t)size andNItems: (size_t)nitems { - return [[OFReadFailedException alloc] initWithObject: obj - andSize: size - andNItems: nitems]; + return [[OFReadOrWriteFailedException alloc] initWithObject: obj + andSize: size + andNItems: nitems]; } +@end +@implementation OFReadFailedException - initWithObject: (id)obj andSize: (size_t)size andNItems: (size_t)nitems { fprintf(stderr, "ERROR: Failed to read %zu items of size %zu in " "object %s!\n", nitems, size, [obj name]); + self = [super init]; + @throw self; + return self; +} +@end + +@implementation OFWriteFailedException +- initWithObject: (id)obj + andSize: (size_t)size + andNItems: (size_t)nitems +{ + fprintf(stderr, "ERROR: Failed to write %zu items of size %zu in " + "object %s!\n", nitems, size, [obj name]); + + self = [super init]; @throw self; - return [super init]; + return self; } @end