The exception that is thrown when there is a NATS error condition. All NATS exception inherit from this class.
Inheritance: System.Exception
Esempio n. 1
0
        public void Flush(int timeout)
        {
            if (timeout <= 0)
            {
                throw new ArgumentOutOfRangeException(
                    "Timeout must be greater than 0",
                    "timeout");
            }

            Channel<bool> ch = new Channel<bool>(1);

            try
            {
                lock (mu)
                {
                    if (isClosed())
                        throw new NATSConnectionClosedException();

                    sendPing(ch);
                }

                bool rv = ch.get(timeout);
                if (!rv)
                {
                    throw new NATSConnectionClosedException();
                }
            }
            catch (Exception e)
            {
                removeFlushEntry(ch);

                // Note, don't call saveFlushException in a finally clause
                // because we don't know if the caller will handle the rethrown 
                // exception.
                if (e is NATSTimeoutException || e is NATSConnectionClosedException)
                {
                    saveFlushException(ch, e);
                    throw;
                }
                else
                {
                    // wrap other system exceptions
                    var ex = new NATSException("Flush error.", e);
                    saveFlushException(ch, ex);
                    throw ex;
                }
            }
        }
Esempio n. 2
0
        // processErr processes any error messages from the server and
        // sets the connection's lastError.
        internal void processErr(MemoryStream errorStream)
        {
            bool invokeDelegates = false;
            Exception ex = null;

            String s = System.Text.Encoding.UTF8.GetString(
                errorStream.ToArray(), 0, (int)errorStream.Position);

            if (IC.STALE_CONNECTION.Equals(s))
            {
                processOpError(new NATSStaleConnectionException());
            }
            else
            {
                ex = new NATSException(s);
                lock (mu)
                {
                    lastEx = ex;

                    if (status != ConnState.CONNECTING)
                    {
                        invokeDelegates = true;
                    }
                }

                close(ConnState.CLOSED, invokeDelegates);
            }
        }
Esempio n. 3
0
        // processErr processes any error messages from the server and
        // sets the connection's lastError.
        internal void processErr(MemoryStream errorStream)
        {
            bool invokeDelegates = false;
            Exception ex = null;

            string s = getNormalizedError(errorStream);

            if (IC.STALE_CONNECTION.Equals(s))
            {
                processOpError(new NATSStaleConnectionException());
            }
            else if (IC.AUTH_TIMEOUT.Equals(s))
            {
                // Protect against a timing issue where an authoriztion error
                // is handled before the connection close from the server.
                // This can happen in reconnect scenarios.
                processOpError(new NATSConnectionException(IC.AUTH_TIMEOUT));
            }
            else
            {
                ex = new NATSException("Error from processErr(): " + s);
                lock (mu)
                {
                    lastEx = ex;

                    if (status != ConnState.CONNECTING)
                    {
                        invokeDelegates = true;
                    }
                }

                close(ConnState.CLOSED, invokeDelegates);
            }
        }