Table of Contents

Class ImportError

Namespace
NumSharp
Assembly
NumSharp.dll

Python's ImportError: a module or a name in it could not be imported. NumSharp itself raises none (.NET binds its assemblies at build time); the class exists so code ported from Python keeps Python's raise ImportError(...) and except ImportError - a plugin or registry that loads by name, a missing optional dependency - with Python's attributes.

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

Remarks

Like CPython's (3.12), it carries msg, name and path; Python's keyword-only name= / path= are the ImportError(string, string, string) constructor. CPython 3.12's undocumented name_from (filled by the import system for its "Did you mean" hints) is not modelled.

It derives from NumSharpException like the other Python-named errors with no .NET counterpart, and Python's own subclass ModuleNotFoundError derives from it, so catch (ImportError) catches both as except ImportError does.

Constructors

ImportError()

Creates the error with Python's text for a bare raise ImportError: an empty Message, as str(ImportError()) is ''; msg, name and path are null.

public ImportError()

ImportError(string)

Creates the error with a message, Python's ImportError(msg): msg is the message.

public ImportError(string message)

Parameters

message string

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

ImportError(string, Exception)

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

public ImportError(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.

ImportError(string, string, string)

Python's ImportError(msg, name=name, path=path): the message plus the module that was being imported and the file that triggered the error.

public ImportError(string message, string name, string path)

Parameters

message string

The text (Python's msg), or null for Python's ImportError(name=..., path=...) without one: Message is then empty, as str() of that error is ''.

name string

The module name (Python's name), or null.

path string

The file path (Python's path), or null.

Remarks

Both keywords are required here (pass null for the one Python's call leaves out): an optional name would make new ImportError(text, null) ambiguous with the inner-exception form.

ImportError(string, string, string, Exception)

Python's raise ImportError(msg, name=name, path=path) from innerException: the keyword form with the exception that caused it.

public ImportError(string message, string name, string path, Exception innerException)

Parameters

message string

The text (Python's msg), or null for none (an empty Message).

name string

The module name (Python's name), or null.

path string

The file path (Python's path), or null.

innerException Exception

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

Properties

msg

The message the error was created with (Python's msg), or null when it was created without one.

public string msg { get; }

Property Value

string

Remarks

Python sets msg only from a lone positional argument; here every message-taking constructor sets it.

name

The name of the module that was being imported (Python's name), or null.

public string name { get; }

Property Value

string

path

The path of the file that triggered the error (Python's path), or null.

public string path { get; }

Property Value

string