Index: src/OFExceptions.h ================================================================== --- src/OFExceptions.h +++ src/OFExceptions.h @@ -203,10 +203,11 @@ */ @interface OFReadOrWriteFailedException: OFException { size_t req_size; size_t req_items; + BOOL has_items; } /** * Creates a new read or write failed exception. * @@ -217,10 +218,20 @@ */ + newWithObject: (id)obj andSize: (size_t)size andNItems: (size_t)nitems; +/** + * Creates a new read or write failed exception. + * + * \param obj The object which caused the exception + * \param size The requested size of the data that couldn't be read / written + * \return A new open file failed exception + */ ++ newWithObject: (id)obj + andSize: (size_t)size; + /** * Initializes an already allocated read or write failed exception. * * \param obj The object which caused the exception * \param size The requested size of the data that couldn't be read / written @@ -229,10 +240,20 @@ */ - initWithObject: (id)obj andSize: (size_t)size andNItems: (size_t)nitems; +/** + * Initializes an already allocated read or write failed exception. + * + * \param obj The object which caused the exception + * \param size The requested size of the data that couldn't be read / written + * \return A new open file failed exception + */ +- initWithObject: (id)obj + andSize: (size_t)size; + /** * \return The requested size of the data that couldn't be read / written */ - (size_t)requestedSize; Index: src/OFExceptions.m ================================================================== --- src/OFExceptions.m +++ src/OFExceptions.m @@ -220,18 +220,38 @@ { return [[self alloc] initWithObject: obj andSize: size andNItems: nitems]; } + ++ newWithObject: (id)obj + andSize: (size_t)size +{ + return [[self alloc] initWithObject: obj + andSize: size]; +} - initWithObject: (id)obj andSize: (size_t)size andNItems: (size_t)nitems { if ((self = [super initWithObject: obj])) { req_size = size; req_items = nitems; + has_items = YES; + } + + return self; +} + +- initWithObject: (id)obj + andSize: (size_t)size +{ + if ((self = [super initWithObject: obj])) { + req_size = size; + req_items = 0; + has_items = NO; } return self; } @@ -250,12 +270,16 @@ - (char*)cString { if (string != NULL) return string;; - asprintf(&string, "Failed to read %zu items of size %zu in object of " - "class %s!", req_items, req_size, [object name]); + if (has_items) + asprintf(&string, "Failed to read %zu items of size %zu in " + "object of class %s!", req_items, req_size, [object name]); + else + asprintf(&string, "Failed to read %zu bytes in object of class " + "%s!", req_size, [object name]); return string; } @end @@ -263,12 +287,16 @@ - (char*)cString { if (string != NULL) return string; - asprintf(&string, "Failed to write %zu items of size %zu in object of " - "class %s!", req_items, req_size, [object name]); + if (has_items) + asprintf(&string, "Failed to write %zu items of size %zu in " + "object of class %s!", req_items, req_size, [object name]); + else + asprintf(&string, "Failed to write %zu bytes in object of " + "class %s!", req_size, [object name]); return string; } @end