Index: src/OFExceptions.h ================================================================== --- src/OFExceptions.h +++ src/OFExceptions.h @@ -27,13 +27,13 @@ * handled like other exceptions, as the exception handling code is not * allowed to allocate ANY memory. */ @interface OFAllocFailedException: OFObject /** - * \return An error message for the exception as a string + * \return A description of the exception */ -- (OFString*)string; +- (OFString*)description; @end /** * \brief The base class for all exceptions in ObjFW * @@ -44,11 +44,11 @@ * either! You have to make sure to dealloc the exception in your \@catch block! */ @interface OFException: OFObject { Class inClass; - OFString *string; + OFString *description; } #ifdef OF_HAVE_PROPERTIES @property (readonly, nonatomic) Class inClass; #endif @@ -73,13 +73,13 @@ * \return The class of the object in which the exception happened */ - (Class)inClass; /** - * \return An error message for the exception as a string + * \return A description of the exception */ -- (OFString*)string; +- (OFString*)description; @end /** * \brief An exception indicating there is not enough memory available. */ Index: src/OFExceptions.m ================================================================== --- src/OFExceptions.m +++ src/OFExceptions.m @@ -135,11 +135,11 @@ @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; [super dealloc]; /* Get rid of a stupid warning */ } -- (OFString*)string +- (OFString*)description { return @"Allocating an object failed!"; } @end @@ -166,23 +166,23 @@ return self; } - (void)dealloc { - [string release]; + [description release]; [super dealloc]; } - (Class)inClass { return inClass; } -- (OFString*)string +- (OFString*)description { - return string; + return @"An exception occurred"; } - autorelease { @throw [OFNotImplementedException newWithClass: isa @@ -206,44 +206,44 @@ requestedSize = size; return self; } -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; if (requestedSize) - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Could not allocate %zu bytes in class %s!", requestedSize, [inClass className]]; else - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Could not allocate enough memory in class %s!", [inClass className]]; - return string; + return description; } - (size_t)requestedSize { return requestedSize; } @end @implementation OFEnumerationMutationException -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Object of class %s was mutated during enumeration!", [inClass className]]; - return string; + return description; } @end @implementation OFMemoryNotPartOfObjectException + newWithClass: (Class)class_ @@ -269,22 +269,22 @@ pointer = ptr; return self; } -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Memory at %p was not allocated as part of object of class %s, " @"thus the memory allocation was not changed! It is also possible " @"that there was an attempt to free the same memory twice.", pointer, [inClass className]]; - return string; + return description; } - (void*)pointer { return pointer; @@ -315,38 +315,38 @@ selector = selector_; return self; } -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"The method %s of class %s is not or not fully implemented!", sel_getName(selector), [inClass className]]; - return string; + return description; } - (SEL)selector { return selector; } @end @implementation OFOutOfRangeException -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Value out of range in class %s!", [inClass className]]; - return string; + return description; } @end @implementation OFInvalidArgumentException + newWithClass: (Class)class_ @@ -372,78 +372,78 @@ selector = selector_; return self; } -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"The argument for method %s of class %s is invalid!", sel_getName(selector), [inClass className]]; - return string; + return description; } - (SEL)selector { return selector; } @end @implementation OFInvalidEncodingException -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"The encoding is invalid for class %s!", [inClass className]]; - return string; + return description; } @end @implementation OFInvalidFormatException -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"The format is invalid for class %s!", [inClass className]]; - return string; + return description; } @end @implementation OFMalformedXMLException -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"The parser in class %s encountered malformed or invalid XML!", [inClass className]]; - return string; + return description; } @end @implementation OFInitializationFailedException -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Initialization failed for class %s!", [inClass className]]; - return string; + return description; } @end @implementation OFOpenFileFailedException + newWithClass: (Class)class_ @@ -487,20 +487,20 @@ [mode release]; [super dealloc]; } -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Failed to open file %s with mode %s in class %s! " ERRFMT, [path cString], [mode cString], [inClass className], ERRPARAM]; - return string; + return description; } - (int)errNo { return errNo; @@ -558,34 +558,34 @@ return requestedSize; } @end @implementation OFReadFailedException -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string;; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Failed to read %zu bytes in class %s! " ERRFMT, requestedSize, [inClass className], ERRPARAM]; - return string; + return description; } @end @implementation OFWriteFailedException -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Failed to write %zu bytes in class %s! " ERRFMT, requestedSize, [inClass className], ERRPARAM]; - return string; + return description; } @end @implementation OFSeekFailedException - initWithClass: (Class)class_ @@ -595,20 +595,20 @@ errNo = GET_ERRNO; return self; } -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Seeking failed in class %s! " ERRFMT, [inClass className], ERRPARAM]; - return string; + return description; } - (int)errNo { return errNo; @@ -652,20 +652,20 @@ [path release]; [super dealloc]; } -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Failed to create directory %s in class %s! " ERRFMT, [path cString], [inClass className], ERRPARAM]; - return string; + return description; } - (int)errNo { return errNo; @@ -719,20 +719,20 @@ [path release]; [super dealloc]; } -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Failed to change mode for file %s to %d in class %s! " ERRFMT, [path cString], mode, [inClass className], ERRPARAM]; - return string; + return description; } - (int)errNo { return errNo; @@ -795,20 +795,20 @@ [path release]; [super dealloc]; } -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Failed to change owner for file %s to %d:%d in class %s! " ERRFMT, [path cString], owner, group, [inClass className], ERRPARAM]; - return string; + return description; } - (int)errNo { return errNo; @@ -873,21 +873,21 @@ [destinationPath release]; [super dealloc]; } -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Failed to copy file %s to %s in class %s! " ERRFMT, [sourcePath cString], [destinationPath cString], [inClass className], ERRPARAM]; - return string; + return description; } - (int)errNo { return errNo; @@ -946,21 +946,21 @@ [destinationPath release]; [super dealloc]; } -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Failed to rename file %s to %s in class %s! " ERRFMT, [sourcePath cString], [destinationPath cString], [inClass className], ERRPARAM]; - return string; + return description; } - (int)errNo { return errNo; @@ -1014,20 +1014,20 @@ [path release]; [super dealloc]; } -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Failed to delete file %s in class %s! " ERRFMT, [path cString], [inClass className], ERRPARAM]; - return string; + return description; } - (int)errNo { return errNo; @@ -1076,20 +1076,20 @@ [path release]; [super dealloc]; } -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Failed to delete directory %s in class %s! " ERRFMT, [path cString], [inClass className], ERRPARAM]; - return string; + return description; } - (int)errNo { return errNo; @@ -1139,21 +1139,21 @@ [destinationPath release]; [super dealloc]; } -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Failed to link file %s to %s in class %s! " ERRFMT, [sourcePath cString], [destinationPath cString], [inClass className], ERRPARAM]; - return string; + return description; } - (int)errNo { return errNo; @@ -1207,21 +1207,21 @@ [destinationPath release]; [super dealloc]; } -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Failed to symlink file %s to %s in class %s! " ERRFMT, [sourcePath cString], [destinationPath cString], [inClass className], ERRPARAM]; - return string; + return description; } - (int)errNo { return errNo; @@ -1238,47 +1238,47 @@ } @end #endif @implementation OFSetOptionFailedException -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Setting an option in class %s failed!", [inClass className]]; - return string; + return description; } @end @implementation OFNotConnectedException -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"The socket of type %s is not connected or bound!", [inClass className]]; - return string; + return description; } @end @implementation OFAlreadyConnectedException -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"The socket of type %s is already connected or bound and thus " @"can't be connected or bound again!", [inClass className]]; - return string; + return description; } @end @implementation OFAddressTranslationFailedException + newWithClass: (Class)class_ @@ -1323,30 +1323,30 @@ [service release]; [super dealloc]; } -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; if (node != nil && service != nil) - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"The service %s on %s could not be translated to an " @"address in class %s. This means that either the node was " @"not found, there is no such service on the node, there " @"was a problem with the name server, there was a problem " @"with your network connection or you specified an invalid " @"node or service. " ERRFMT, [service cString], [node cString], [inClass className], AT_ERRPARAM]; else - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"An address translation failed in class %s! " ERRFMT, [inClass className], AT_ERRPARAM]; - return string; + return description; } - (int)errNo { return errNo; @@ -1405,21 +1405,21 @@ [service release]; [super dealloc]; } -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"A connection to service %s on node %s could not be established " @"in class %s! " ERRFMT, [service cString], [node cString], [inClass className], ERRPARAM]; - return string; + return description; } - (int)errNo { return errNo; @@ -1482,21 +1482,21 @@ [service release]; [super dealloc]; } -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Binding service %s on node %s using family %d failed in class " @"%s! " ERRFMT, [service cString], [node cString], family, [inClass className], ERRPARAM]; - return string; + return description; } - (int)errNo { return errNo; @@ -1543,20 +1543,20 @@ errNo = GET_SOCK_ERRNO; return self; } -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Failed to listen in socket of type %s with a back log of %d! " ERRFMT, [inClass className], backLog, ERRPARAM]; - return string; + return description; } - (int)errNo { return errNo; @@ -1576,106 +1576,106 @@ errNo = GET_SOCK_ERRNO; return self; } -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Failed to accept connection in socket of type %s! " ERRFMT, [inClass className], ERRPARAM]; - return string; + return description; } - (int)errNo { return errNo; } @end @implementation OFThreadStartFailedException -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Starting a thread of class %s failed!", [inClass className]]; - return string; + return description; } @end @implementation OFThreadJoinFailedException -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Joining a thread of class %s failed! Most likely, another thread " @"already waits for the thread to join.", [inClass className]]; - return string; + return description; } @end @implementation OFThreadStillRunningException -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"Deallocation of a thread of type %s was tried, even though it " @"was still running", [inClass className]]; - return string; + return description; } @end @implementation OFMutexLockFailedException -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"A mutex could not be locked in class %s", [inClass className]]; - return string; + return description; } @end @implementation OFMutexUnlockFailedException -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"A mutex could not be unlocked in class %s", [inClass className]]; - return string; + return description; } @end @implementation OFHashAlreadyCalculatedException -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"The hash has already been calculated in class %s and thus no new " @"data can be added", [inClass className]]; - return string; + return description; } @end @implementation OFUnboundNamespaceException + newWithClass: (Class)class_ @@ -1736,25 +1736,25 @@ [prefix release]; [super dealloc]; } -- (OFString*)string +- (OFString*)description { - if (string != nil) - return string; + if (description != nil) + return description; if (ns != nil) - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"The namespace %s is not bound in class %s", [inClass className]]; else if (prefix != nil) - string = [[OFString alloc] initWithFormat: + description = [[OFString alloc] initWithFormat: @"The prefix %s is not bound to any namespace in %s", [inClass className]]; - return string; + return description; } - (OFString*)namespace { return ns;