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

ErrorCheck() static private method

Shortcut for (pointer == NULL) -> throw PythonException
static private ErrorCheck ( IntPtr pointer ) : void
pointer System.IntPtr Pointer to a Python object
return void
        internal static unsafe void ErrorCheck(IntPtr pointer)
        {
            if (pointer == IntPtr.Zero)
            {
                throw new PythonException();
            }
        }

Usage Example

Example #1
0
        /// <summary>
        /// Initialization performed on startup of the Python runtime.
        /// </summary>
        internal static void Initialize()
        {
            string exceptionsModuleName = Runtime.IsPython3 ? "builtins" : "exceptions";

            exceptions_module = Runtime.PyImport_ImportModule(exceptionsModuleName);

            Exceptions.ErrorCheck(exceptions_module);
            warnings_module = Runtime.PyImport_ImportModule("warnings");
            Exceptions.ErrorCheck(warnings_module);
            Type type = typeof(Exceptions);

            foreach (FieldInfo fi in type.GetFields(BindingFlags.Public | BindingFlags.Static))
            {
                IntPtr op = Runtime.PyObject_GetAttrString(exceptions_module, fi.Name);
                if (op != IntPtr.Zero)
                {
                    fi.SetValue(type, op);
                }
                else
                {
                    fi.SetValue(type, IntPtr.Zero);
                    DebugUtil.Print($"Unknown exception: {fi.Name}");
                }
            }
            Runtime.PyErr_Clear();
        }
All Usage Examples Of Python.Runtime.Exceptions::ErrorCheck