/// <summary>
        /// Invoked by the AMQProtocolSession when a protocol session exception has occurred.
        /// This method sends the exception to a JMS exception listener, if configured, and
        /// propagates the exception to sessions, which in turn will propagate to consumers.
        /// This allows synchronous consumers to have exceptions thrown to them.
        /// </summary>
        /// <param name="cause">the exception</param>
        public void ExceptionReceived(Exception cause)
        {
            if (_exceptionListener != null)
            {
                // Listener expects one of these...
                QpidException xe;

                if (cause is QpidException)
                {
                    xe = (QpidException)cause;
                }
                else
                {
                    xe = new QpidException("Exception thrown against " + ToString() + ": " + cause, cause);
                }
                // in the case of an IOException, MINA has closed the protocol session so we set _closed to true
                // so that any generic client code that tries to close the connection will not mess up this error
                // handling sequence
                if (cause is IOException)
                {
                    Interlocked.Exchange(ref _closed, CLOSED);
                }
#if __MonoCS__
                _exceptionListener(xe);
#else
                _exceptionListener.Invoke(xe);
#endif
            }
            else
            {
                _log.Error("Connection exception: " + cause);
            }

            // An undelivered is not fatal to the connections usability.
            if (!(cause is AMQUndeliveredException))
            {
                Interlocked.Exchange(ref _closed, CLOSED);
                CloseAllSessions(cause);
            }
            else
            {
                ;
            }
        }