Class OverflowError
- Namespace
- NumSharp
- Assembly
- NumSharp.dll
Python's OverflowError: a number too large for the type it must become. NumSharp raises it where NumPy
and CPython do, with their text: a Python int that does not fit the target (Python integer 300 out of bounds
for uint8, Python int too large to convert to C long), a float infinity converted to an integer
(cannot convert float infinity to integer), an int too large for a float (int too large to convert to
float), a string repeat or pad whose result cannot be sized (Overflow encountered in string multiply),
and the random generators' range checks (Range exceeds valid bounds).
public class OverflowError : ArithmeticError, ISerializable, INumSharpException
- Inheritance
-
OverflowError
- Implements
- Inherited Members
Remarks
A subclass of ArithmeticError (Python's MRO: OverflowError → ArithmeticError → Exception),
so catch (ArithmeticError) and catch (ArithmeticException) catch it.
Footgun: it is NOT .NET's OverflowException, and a catch (OverflowException) written before
NumSharp raised Python's class misses it; catch OverflowError (or
ArithmeticException for both). A checked .NET conversion still throws
OverflowException; NumSharp's own size limits (a managed array past MaxValue,
a Char8 conversion) keep theirs.
Constructors
OverflowError()
Creates the error with Python's text for a bare raise OverflowError: an empty
Message, as str(OverflowError()) is ''.
public OverflowError()
Remarks
ToString() then starts with the class name alone, as Python's traceback prints a
bare OverflowError; prefer a message that names the value and its target.
OverflowError(string)
Creates the error with NumPy's (or CPython's) message.
public OverflowError(string message)
Parameters
messagestringThe text, verbatim: Python's
str()of the error (Python integer 300 out of bounds for uint8).
OverflowError(string, Exception)
Creates the error with a message and the exception that caused it: Python's raise OverflowError(message)
from innerException, the cause kept in InnerException as Python keeps it in
cause.
public OverflowError(string message, Exception innerException)
Parameters
messagestringThe text, verbatim: Python's
str()of the error.innerExceptionExceptionThe exception that led to this one (a .NET OverflowException from a
checkedconversion, for example), or null for none.