Python.Runtime.Exceptions.SetError C# (CSharp) Method

SetError() public static method

SetError Method
Sets the current Python exception given a CLR exception object. The CLR exception instance is wrapped as a Python object, allowing it to be handled naturally from Python.
public static SetError ( Exception e ) : void
e System.Exception
return void
        public static void SetError(Exception e)
        {
            // Because delegates allow arbitrary nestings of Python calling
            // managed calling Python calling... etc. it is possible that we
            // might get a managed exception raised that is a wrapper for a
            // Python exception. In that case we'd rather have the real thing.

            PythonException pe = e as PythonException;
            if (pe != null)
            {
                Runtime.PyErr_SetObject(pe.PyType, pe.PyValue);
                return;
            }

            IntPtr op = CLRObject.GetInstHandle(e);
            IntPtr etype = Runtime.PyObject_GetAttrString(op, "__class__");
            Runtime.PyErr_SetObject(etype, op);
            Runtime.XDecref(etype);
            Runtime.XDecref(op);
        }

Same methods

Exceptions::SetError ( IntPtr ob, IntPtr value ) : void
Exceptions::SetError ( IntPtr ob, string value ) : void

Usage Example

Example #1
0
        //====================================================================
        // Implements __call__ for reflected generic types.
        //====================================================================

        public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw)
        {
            Exceptions.SetError(Exceptions.TypeError,
                                "object is not callable");
            return(IntPtr.Zero);
        }
All Usage Examples Of Python.Runtime.Exceptions::SetError