ToPython() static private method

Given a CLR exception returns the Python exception which most closely maps to the CLR exception.
static private ToPython ( System clrException ) : object
clrException System
return object
        public int GetExitCode(out object otherCode)
        {
            otherCode = null;
            object pyObj = PythonExceptions.ToPython(this);

            object      args;
            PythonTuple t;

            if (!PythonOps.TryGetBoundAttr(pyObj, "args", out args) ||
                (t = args as PythonTuple) == null ||
                t.__len__() == 0)
            {
                return(0);
            }
            else if (Builtin.isinstance(t[0], TypeCache.Int32))
            {
                return(Converter.ConvertToInt32(t[0]));
            }
            else if (Builtin.isinstance(t[0], TypeCache.BigInteger))
            {
                var b = Converter.ConvertToBigInteger(t[0]);
                if (b > int.MaxValue || b < int.MinValue)
                {
                    return(-1);
                }
                return((int)b);
            }

            otherCode = t[0];
            return(1);
        }
示例#2
0
        public int GetExitCode(out object otherCode) {
            otherCode = null;
            object pyObj = PythonExceptions.ToPython(this);

            object args;
            PythonTuple t;

            if (!PythonOps.TryGetBoundAttr(pyObj, "args", out args) ||
                (t = args as PythonTuple) == null ||
                t.__len__() == 0) {
                return 0;
            } else if (Builtin.isinstance(t[0], TypeCache.Int32)) {
                return Converter.ConvertToInt32(t[0]);
            }

            otherCode = t[0];
            return 1;
        }