Index: src/OFExceptions.h ================================================================== --- src/OFExceptions.h +++ src/OFExceptions.h @@ -42,11 +42,11 @@ * \return The object that caused the exception */ - (id)object; /** - * \return An error message for the exception as a C String + * \return An error message for the exception as a C string */ - (const char*)cString; @end /** @@ -74,11 +74,11 @@ */ - initWithObject: (id)obj andSize: (size_t)size; /** - * \return An error message for the exception as a C String + * \return An error message for the exception as a C string */ - (const char*)cString; /** * \return The size of the memoory that couldn't be allocated @@ -111,11 +111,11 @@ */ - initWithObject: (id)obj andPointer: (void*)ptr; /** - * \return An error message for the exception as a C String + * \return An error message for the exception as a C string */ - (const char*)cString; /** * \return A pointer to the memory which is not part of the object @@ -126,23 +126,58 @@ /** * An OFException indicating the given value is out of range. */ @interface OFOutOfRangeException: OFException {} /** - * \return An error message for the exception as a C String + * \return An error message for the exception as a C string */ - (const char*)cString; @end /** * An OFException indicating that the encoding is invalid for this object. */ @interface OFInvalidEncodingException: OFException {} /** - * \return An error message for the exception as a C String + * \return An error message for the exception as a C string + */ +- (const char*)cString; +@end + +/** + * An OFException indicating that initializing something failed. + */ +@interface OFInitializationFailedException: OFException +{ + Class class; +} + +/** + * Creates a new exception. + * + * \param class The class which caused the exception + * \return A new exception + */ ++ newWithClass: (Class)class; + +/** + * Initializes an already allocated OFException. + * + * \param obj The object which caused the exception + * \return An initialized OFException + */ +- initWithClass: (Class)class; + +/** + * \return An error message for the exception as a C string */ - (const char*)cString; + +/** + * \return The class which caused the exception + */ +- (Class)class; @end /** * An OFException indicating the file couldn't be opened. */ @@ -176,11 +211,11 @@ andMode: (const char*)mode; - free; /** - * \return An error message for the exception as a C String + * \return An error message for the exception as a C string */ - (const char*)cString; /** * \return The errno from when the exception was created @@ -273,21 +308,21 @@ /** * An OFException indicating a read to the file failed. */ @interface OFReadFailedException: OFReadOrWriteFailedException {} /** - * \return An error message for the exception as a C String + * \return An error message for the exception as a C string */ - (const char*)cString; @end /** * An OFException indicating a write to the file failed. */ @interface OFWriteFailedException: OFReadOrWriteFailedException {} /** - * \return An error message for the exception as a C String + * \return An error message for the exception as a C string */ - (const char*)cString; @end /** Index: src/OFExceptions.m ================================================================== --- src/OFExceptions.m +++ src/OFExceptions.m @@ -151,10 +151,43 @@ [object name]); return string; } @end + +@implementation OFInitializationFailedException ++ newWithClass: (Class)class_ +{ + return [[self alloc] initWithClass: class_]; +} + +- initWithClass: (Class)class_ +{ + if ((self = [super init])) { + object = nil; + string = NULL; + class = class_; + } + + return self; +} + +- (const char*)cString +{ + if (string != NULL) + return string; + + asprintf(&string, "Initialization failed for class %s!", [class name]); + + return string; +} + +- (Class)class +{ + return class; +} +@end @implementation OFOpenFileFailedException + newWithObject: (id)obj andPath: (const char*)path_ andMode: (const char*)mode_