예제 #1
0
        public virtual RobotRaconteurException DownCastException(RobotRaconteurException exp)
        {
            try
            {
                if (!exp.Error.Contains("."))
                {
                    return(exp);
                }

                ServiceFactory f = null;

                var s = ServiceDefinitionUtil.SplitQualifiedName(exp.Error);

                if (context != null)
                {
                    if (!context.TryGetPulledServiceType(s.Item1, out f))
                    {
                        f = null;
                    }
                }
                if (f == null)
                {
                    if (!node.TryGetServiceType(s.Item1, out f))
                    {
                        f = null;
                    }
                }

                if (f == null)
                {
                    return(exp);
                }

                return(f.DownCastException(exp));
            }
            catch (Exception)
            {
                return(null);
            }
        }
예제 #2
0
        public static void ExceptionToMessageEntry(Exception exception, MessageEntry entry)
        {
            if (exception is InvalidOperationException)
            {
                entry.Error = MessageErrorType.InvalidOperation;
                entry.AddElement("errorname", "RobotRaconteur.InvalidOperation");
                entry.AddElement("errorstring", exception.Message);
                return;
            }

            if (exception is ArgumentException)
            {
                entry.Error = MessageErrorType.InvalidArgument;
                entry.AddElement("errorname", "RobotRaconteur.InvalidArgument");
                entry.AddElement("errorstring", exception.Message);
                return;
            }

            if (exception is NullReferenceException)
            {
                entry.Error = MessageErrorType.NullValue;
                entry.AddElement("errorname", "RobotRaconteur.NullValue");
                entry.AddElement("errorstring", exception.Message);
                return;
            }

            if (exception is NotImplementedException)
            {
                entry.Error = MessageErrorType.NotImplementedError;
                entry.AddElement("errorname", "RobotRaconteur.NotImplementedError");
                entry.AddElement("errorstring", exception.Message);
                return;
            }

            if (exception is ArgumentOutOfRangeException)
            {
                entry.Error = MessageErrorType.OutOfRange;
                entry.AddElement("errorname", "RobotRaconteur.OutOfRange");
                entry.AddElement("errorstring", exception.Message);
                return;
            }

            if (exception is KeyNotFoundException)
            {
                entry.Error = MessageErrorType.KeyNotFound;
                entry.AddElement("errorname", "RobotRaconteur.KeyNotFound");
                entry.AddElement("errorstring", exception.Message);
                return;
            }

            if (exception is System.IO.IOException)
            {
                entry.Error = MessageErrorType.IOError;
                entry.AddElement("errorname", "RobotRaconteur.IOError");
                entry.AddElement("errorstring", exception.Message);
                return;
            }

            if (exception is RobotRaconteurException)
            {
                RobotRaconteurException r = (RobotRaconteurException)exception;
                entry.Error = r.ErrorCode;
                entry.AddElement("errorname", r.Error);
                entry.AddElement("errorstring", r.Message);
            }
            else
            {
                entry.Error = MessageErrorType.RemoteError;
                entry.AddElement("errorname", exception.GetType().ToString());
                entry.AddElement("errorstring", exception.Message);
            }
        }