Index: src/OFExceptions.h ================================================================== --- src/OFExceptions.h +++ src/OFExceptions.h @@ -132,10 +132,20 @@ /** * An OFException indicating the given value is out of range. */ @interface OFOutOfRangeException: OFException {} /** + * \return An error message for the exception as a C String + */ +- (char*)cString; +@end + +/** + * An OFException indicating that the conversation between two charsets failed. + */ +@interface OFCharsetConversionFailedException: OFException {} +/** * \return An error message for the exception as a C String */ - (char*)cString; @end Index: src/OFExceptions.m ================================================================== --- src/OFExceptions.m +++ src/OFExceptions.m @@ -140,10 +140,23 @@ return string; asprintf(&string, "Value out of range in object of class %s!", object != nil ? [object name] : "(null)"); + return string; +} +@end + +@implementation OFCharsetConversionFailedException +- (char*)cString +{ + if (string != NULL) + return string; + + asprintf(&string, "Charset conversion failed in object of classs %s!", + [object name]); + return string; } @end @implementation OFOpenFileFailedException Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -51,13 +51,13 @@ if (str == NULL) { length = 0; string = NULL; } else { if ((length = mbstowcs(NULL, str, 0)) == (size_t)-1) { - /* FIXME: Throw exception */ [super free]; - return nil; + @throw [OFCharsetConversionFailedException + newWithObject: nil]; } string = [self getMemForNItems: length + 1 ofSize: sizeof(wchar_t)]; @@ -91,21 +91,18 @@ - (char*)getCString { char *str; size_t len; - if ((len = wcstombs(NULL, string, 0)) == (size_t)-1) { - /* FIXME: Throw exception */ - return NULL; - } + if ((len = wcstombs(NULL, string, 0)) == (size_t)-1) + @throw [OFCharsetConversionFailedException newWithObject: self]; str = [self getMemWithSize: len + 1]; if (wcstombs(str, string, len + 1) != len) { - /* FIXME: Throw exception */ [self freeMem: str]; - return NULL; + @throw [OFCharsetConversionFailedException newWithObject: self]; } return str; } @@ -146,22 +143,19 @@ size_t newlen, strlength; if (string == NULL) return [self setTo: [OFString newFromCString: str]]; - if ((strlength = mbstowcs(NULL, str, 0)) == (size_t)-1) { - /* FIXME: Throw exception */ - return nil; - } + if ((strlength = mbstowcs(NULL, str, 0)) == (size_t)-1) + @throw [OFCharsetConversionFailedException newWithObject: self]; tmpstr = [self getMemForNItems: strlength + 1 ofSize: sizeof(wchar_t)]; if (mbstowcs(tmpstr, str, strlength) != strlength) { - /* FIXME: Throw exception */ [self freeMem: tmpstr]; - return nil; + @throw [OFCharsetConversionFailedException newWithObject: self]; } newlen = length + strlength; newstr = [self resizeMem: string toNItems: newlen + 1