Class AttributeError
- Namespace
- NumSharp
- Assembly
- NumSharp.dll
Exception that corresponds to Python/NumPy's AttributeError. Raised when an attribute reference or assignment fails.
public class AttributeError : NumSharpException, ISerializable, INumSharpException
- Inheritance
-
AttributeError
- Implements
- Inherited Members
Remarks
Mirrors Python's AttributeError for API compatibility. In NumSharp this is raised where NumPy
itself raises AttributeError — notably np.savetxt(fname, X, fmt=[...]) when the
list/tuple of formats is not the same length as the number of columns, which reaches
_npyio_impl.py's raise AttributeError(f'fmt has wrong shape. {str(fmt)}').
Like Python's, it carries name and obj: the attribute that was looked up and the
object it was looked up on. CPython fills both when an attribute lookup fails ('NoneType' object has no
attribute 'join'), and NumSharp's raise sites that stand for such a lookup fill them too; an explicit
raise AttributeError("...") in NumPy's Python code leaves both None, and so does NumSharp's twin.
Constructors
AttributeError()
Creates the error with Python's text for a bare raise AttributeError: an empty
Message, as str(AttributeError()) is ''.
public AttributeError()
Remarks
ToString() then starts with the class name alone, as Python's traceback prints a
bare AttributeError; prefer a message that names the attribute.
AttributeError(string)
public AttributeError(string message)
Parameters
messagestringThe text, verbatim: Python's
str()of the error.
AttributeError(string, Exception)
Creates the error with a message and the exception that caused it: Python's raise
AttributeError(message) from innerException, the cause kept in InnerException as
Python keeps it in cause; name and obj stay null.
public AttributeError(string message, Exception innerException)
Parameters
messagestringThe text, verbatim: Python's
str()of the error.innerExceptionExceptionThe exception that led to this one, or null for none.
AttributeError(string, string, object)
Python's AttributeError(message, name=name, obj=obj): the message, the attribute's name and the object
the lookup ran on, which a caller reads from name / obj without parsing the text.
public AttributeError(string message, string name, object obj)
Parameters
messagestringThe text, verbatim (
'NoneType' object has no attribute 'join').namestringThe attribute that was looked up, or null for none (Python's
name=None).objobjectThe object it was looked up on, or null (Python's
None: both "no object given" and a lookup onNoneitself, as in Python, where the two read the same).
Remarks
Python's name and obj are keyword-only; the C# form takes both positionally (pass null for
the one you lack), so it never collides with AttributeError(string, Exception).
Properties
name
The attribute that was looked up (Python's name), or null when the raiser did not give it.
public string name { get; }
Property Value
obj
The object the attribute was looked up on (Python's obj), or null when the raiser did not give it or
the object was None.
public object obj { get; }
Property Value
Remarks
Footgun: it holds a live reference to that object (an NDArray, for example) for as long as the exception is kept, as Python's does; drop a caught error you store instead of keeping its object alive by accident.