Example #1
0
        void ProcessException(uint callId, uint type, BufferView data)
        {
            PendingCall callInfo = FetchPendingCall(callId);

            if (callInfo == null)
            {
                // Received a timeouted (or invalid) answer
                ProtocolError();
                return;
            }
            if (!callInfo.Call.HasException(type))
            {
                // Received an invalid exception type
                ProtocolError();
                return;
            }

            // Get exception definition
            Registry.RegisteredException exception = Registry.GetException(type);
            if (exception == null)
            {
                ProtocolError();
                return;
            }

            // Read the incoming data
            object inflatedData;

            try {
                inflatedData = InflateData.Inflate(data, exception.DataFormat);
            } catch {
                ProtocolError();
                return;
            }

            // Clear the timeout
            if (callInfo.Interval != null)
            {
                callInfo.Interval.Stop();
            }

            // Call the callback
            if (callInfo.OnException != null)
            {
                callInfo.OnException(this, (int)type, inflatedData);
            }
        }
Example #2
0
        /// <summary>
        /// Create a new exception. It must be declared in the Registry
        /// </summary>
        /// <param name="type">The type of the exception</param>
        /// <param name="data">The data pack</param>
        public CallException(uint type, Data data)
        {
            // Validate the exception type
            Registry.RegisteredException entry = Registry.GetException(type);
            if (entry == null)
            {
                throw new ArgumentException("Invalid exception type " + type);
            }

            // Validate the data format
            if (data.Format != entry.DataFormat.FormatString)
            {
                throw new ArgumentException("Invalid data type '" + data.Format + "' for exception " + type);
            }

            Type = type;
            Data = data;
        }