PyErr_Occurred() private method

private PyErr_Occurred ( ) : int
return int
Esempio n. 1
0
        /// <remarks>
        /// Unlike <see cref="ToManaged(BorrowedReference, Type, out object?, bool)"/>,
        /// this method does not have a <c>setError</c> parameter, because it should
        /// only be called after <see cref="ToManaged(BorrowedReference, Type, out object?, bool)"/>.
        /// </remarks>
        internal static bool ToManagedExplicit(BorrowedReference value, Type obType,
                                               out object?result)
        {
            result = null;

            // this method would potentially clean any existing error resulting in information loss
            Debug.Assert(Runtime.PyErr_Occurred() == null);

            string?converterName =
                IsInteger(obType) ? "__int__"
                : IsFloatingNumber(obType) ? "__float__"
                : null;

            if (converterName is null)
            {
                return(false);
            }

            Debug.Assert(obType.IsPrimitive);

            using var converter = Runtime.PyObject_GetAttrString(value, converterName);
            if (converter.IsNull())
            {
                Exceptions.Clear();
                return(false);
            }

            using var explicitlyCoerced = Runtime.PyObject_CallObject(converter.Borrow(), BorrowedReference.Null);
            if (explicitlyCoerced.IsNull())
            {
                Exceptions.Clear();
                return(false);
            }
            return(ToPrimitive(explicitlyCoerced.Borrow(), obType, out result, false));
        }
Esempio n. 2
0
 internal static void Throw()
 {
     using (GIL())
     {
         if (Runtime.PyErr_Occurred() != 0)
         {
             throw new PythonException();
         }
     }
 }
Esempio n. 3
0
 /// <summary>
 /// ErrorOccurred Method
 /// </summary>
 /// <remarks>
 /// Returns true if an exception occurred in the Python runtime.
 /// This is a wrapper for the Python PyErr_Occurred call.
 /// </remarks>
 public static bool ErrorOccurred()
 {
     return(Runtime.PyErr_Occurred() != 0);
 }
Esempio n. 4
0
 /// <summary>
 /// ErrorOccurred Method
 /// </summary>
 /// <remarks>
 /// Returns true if an exception occurred in the Python runtime.
 /// This is a wrapper for the Python PyErr_Occurred call.
 /// </remarks>
 public static bool ErrorOccurred()
 {
     return(Runtime.PyErr_Occurred() != IntPtr.Zero);
 }
Esempio n. 5
0
 /// <summary>
 /// ErrorOccurred Method
 /// </summary>
 /// <remarks>
 /// Returns true if an exception occurred in the Python runtime.
 /// This is a wrapper for the Python PyErr_Occurred call.
 /// </remarks>
 public static bool ErrorOccurred()
 {
     return Runtime.PyErr_Occurred() != null;
 }