Index: src/exceptions/OFAddressTranslationFailedException.h ================================================================== --- src/exceptions/OFAddressTranslationFailedException.h +++ src/exceptions/OFAddressTranslationFailedException.h @@ -47,10 +47,18 @@ + (instancetype)exceptionWithSocket: (OFTCPSocket*)socket; /*! * @brief Creates a new, autoreleased address translation failed exception. * + * @param host The host for which translation was requested + * @return A new, autoreleased address translation failed exception + */ ++ (instancetype)exceptionWithHost: (OFString*)host; + +/*! + * @brief Creates a new, autoreleased address translation failed exception. + * * @param host The host for which translation was requested * @param socket The socket which could not translate the address * @return A new, autoreleased address translation failed exception */ + (instancetype)exceptionWithHost: (OFString*)host @@ -62,10 +70,18 @@ * @param socket The socket which could not translate the address * @return An initialized address translation failed exception */ - initWithSocket: (OFTCPSocket*)socket; +/*! + * @brief Initializes an already allocated address translation failed exception. + * + * @param host The host for which translation was requested + * @return An initialized address translation failed exception + */ +- initWithHost: (OFString*)host; + /*! * @brief Initializes an already allocated address translation failed exception. * * @param host The host for which translation was requested * @param socket The socket which could not translate the address Index: src/exceptions/OFAddressTranslationFailedException.m ================================================================== --- src/exceptions/OFAddressTranslationFailedException.m +++ src/exceptions/OFAddressTranslationFailedException.m @@ -25,43 +25,33 @@ @implementation OFAddressTranslationFailedException + (instancetype)exceptionWithSocket: (OFTCPSocket*)socket { return [[[self alloc] initWithSocket: socket] autorelease]; } + ++ (instancetype)exceptionWithHost: (OFString*)host +{ + return [[[self alloc] initWithHost: host] autorelease]; +} + (instancetype)exceptionWithHost: (OFString*)host socket: (OFTCPSocket*)socket { return [[[self alloc] initWithHost: host socket: socket] autorelease]; } -- init -{ - @try { - [self doesNotRecognizeSelector: _cmd]; - } @catch (id e) { - [self release]; - @throw e; - } - - abort(); -} - - initWithSocket: (OFTCPSocket*)socket { - self = [super init]; - - @try { - _socket = [socket retain]; - _errNo = GET_AT_ERRNO; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; + return [self initWithHost: nil + socket: socket]; +} + +- initWithHost: (OFString*)host +{ + return [self initWithHost: host + socket: nil]; } - initWithHost: (OFString*)host socket: (OFTCPSocket*)socket { @@ -87,22 +77,33 @@ [super dealloc]; } - (OFString*)description { - if (_host != nil) + if (_host != nil && _socket != nil) return [OFString stringWithFormat: @"The host %@ could not be translated to an address for a " @"socket of type %@. This means that either the host was " @"not found, there was a problem with the name server, " @"there was a problem with your network connection or you " @"specified an invalid host. " ERRFMT, _host, [_socket class], AT_ERRPARAM]; + else if (_socket != nil) + return [OFString stringWithFormat: + @"An address could not be translated for a socket of type " + @"%@! " ERRFMT, [_socket class], + AT_ERRPARAM]; + else if (_host != nil) + return [OFString stringWithFormat: + @"The host %@ could not be translated to an address. This " + @"means that either the host was not found, there was a " + @"problem with the name server, there was a problem with " + @"your network connection or you specified an invalid " + @"host. " ERRFMT, _host, AT_ERRPARAM]; else return [OFString stringWithFormat: - @"An address could not be translated translation for a " - @"socket of type %@! " ERRFMT, [_socket class], + @"An address could not be translated! " ERRFMT, AT_ERRPARAM]; } - (OFString*)host {