Table of Contents

Class NameError

Namespace
NumSharp
Assembly
NumSharp.dll

Exception that corresponds to Python/NumPy's NameError. Raised when a name referenced by value is not defined.

public class NameError : NumSharpException, ISerializable, INumSharpException
Inheritance
NameError
Implements
Derived
Inherited Members

Remarks

Mirrors Python's NameError for API compatibility. In NumSharp this is raised where NumPy itself raises NameError — notably np.bmat("A,B; C,D", …), whose string form resolves each whitespace/comma-separated token as a variable name and reaches defmatrix.py's raise NameError(f"name {col!r} is not defined") when a token is absent from the supplied name dictionaries (this also fires for numeric literals, since a token such as "1" is treated as a name).

Like Python's, it carries name: the undefined name when the raiser supplies it (CPython's own lookup failures do; NumPy's np.bmat passes only the text, so its name is null, as e.name is None there). Python's subclass UnboundLocalError derives from it.

Constructors

NameError()

Creates the error with Python's text for a bare raise NameError: an empty Message, as str(NameError()) is ''.

public NameError()

Remarks

ToString() then starts with the class name alone, as Python's traceback prints a bare NameError; prefer a message that names the undefined name.

NameError(string)

Creates the error with NumPy's (or the port's) message; name stays null.

public NameError(string message)

Parameters

message string

The text, verbatim: Python's str() of the error.

NameError(string, Exception)

Creates the error with a message and the exception that caused it: Python's raise NameError(message) from innerException, the cause kept in InnerException as Python keeps it in cause; name stays null.

public NameError(string message, Exception innerException)

Parameters

message string

The text, verbatim: Python's str() of the error.

innerException Exception

The exception that led to this one, or null for none.

NameError(string, string)

Python's NameError(message, name=name): the message and the undefined name, which a caller reads from name without parsing the text.

public NameError(string message, string name)

Parameters

message string

The text, verbatim (name 'x' is not defined).

name string

The name that is not defined, or null for none (Python's name=None).

Remarks

Python's name is keyword-only: NameError('m', 'x') in Python is a two-argument error whose text is ('m', 'x'), while this constructor's second argument IS the name. Footgun: a literal null second argument is ambiguous with NameError(string, Exception) (CS0121); cast it ((string)null) or use the one-argument form.

Properties

name

The name that was not defined (Python's name attribute), or null when the raiser did not give it (every constructor but NameError(string, string)).

public string name { get; }

Property Value

string