Index: src/XMPPConnection.h ================================================================== --- src/XMPPConnection.h +++ src/XMPPConnection.h @@ -114,10 +114,22 @@ * * \param connection The connection that was closed */ - (void)connectionWasClosed: (XMPPConnection*)connection; +/** + * \brief This callback is called when the connection threw an exception. + * + * This is only called for connections on which \ref handleConnection: has been + * called. + * + * \param connection The connection which threw an exception + * \param exception The exception the connection threw + */ +- (void)connection: (XMPPConnection*)connection + didThrowException: (OFException*)exception; + /** * \brief This callback is called when the connection is about to upgrade to * TLS. * * \param connection The connection that will upgraded to TLS Index: src/XMPPConnection.m ================================================================== --- src/XMPPConnection.m +++ src/XMPPConnection.m @@ -342,18 +342,31 @@ didReadIntoBuffer: (char*)buffer length: (size_t)length exception: (OFException*)exception { if (exception != nil) { + [delegates broadcastSelector: @selector(connection: + didThrowException::) + withObject: self + withObject: exception]; + [self close]; + return NO; + } + + @try { + if (![self XMPP_parseBuffer: buffer + length: length]) + return NO; + } @catch (id e) { + [delegates broadcastSelector: @selector(connection: + didThrowException::) + withObject: self + withObject: e]; [self close]; return NO; } - if (![self XMPP_parseBuffer: buffer - length: length]) - return NO; - if (oldParser != nil || oldElementBuilder != nil) { [oldParser release]; [oldElementBuilder release]; oldParser = nil;