Skip to content

example_fgen_basic.pyfgen_runtime.exceptions#

Runtime exceptions

Classes:

Name Description
CompiledExtensionNotFoundError

Raised when a compiled extension can't be imported i.e. found

MissingOptionalDependencyError

Raised when an optional dependency is missing

NotInitialisedError

Raised when the wrapper around the Fortran module hasn't been initialised yet

UnallocatedMemoryError

Raised when we try to access memory that has not yet been allocated

WrapperError

Base exception for errors that arise from wrapper functionality

CompiledExtensionNotFoundError #

Bases: ImportError

Raised when a compiled extension can't be imported i.e. found

Source code in src/example_fgen_basic/pyfgen_runtime/exceptions.py
class CompiledExtensionNotFoundError(ImportError):
    """
    Raised when a compiled extension can't be imported i.e. found
    """

    def __init__(self, compiled_extension_name: str):
        error_msg = f"Could not find compiled extension {compiled_extension_name!r}"

        super().__init__(error_msg)

MissingOptionalDependencyError #

Bases: ImportError

Raised when an optional dependency is missing

For example, plotting dependencies like matplotlib

Methods:

Name Description
__init__

Initialise the error

Source code in src/example_fgen_basic/pyfgen_runtime/exceptions.py
class MissingOptionalDependencyError(ImportError):
    """
    Raised when an optional dependency is missing

    For example, plotting dependencies like matplotlib
    """

    def __init__(self, callable_name: str, requirement: str) -> None:
        """
        Initialise the error

        Parameters
        ----------
        callable_name
            The name of the callable that requires the dependency

        requirement
            The name of the requirement
        """
        error_msg = f"`{callable_name}` requires {requirement} to be installed"
        super().__init__(error_msg)

__init__ #

__init__(callable_name: str, requirement: str) -> None

Initialise the error

Parameters:

Name Type Description Default
callable_name str

The name of the callable that requires the dependency

required
requirement str

The name of the requirement

required
Source code in src/example_fgen_basic/pyfgen_runtime/exceptions.py
def __init__(self, callable_name: str, requirement: str) -> None:
    """
    Initialise the error

    Parameters
    ----------
    callable_name
        The name of the callable that requires the dependency

    requirement
        The name of the requirement
    """
    error_msg = f"`{callable_name}` requires {requirement} to be installed"
    super().__init__(error_msg)

NotInitialisedError #

Bases: WrapperError

Raised when the wrapper around the Fortran module hasn't been initialised yet

Source code in src/example_fgen_basic/pyfgen_runtime/exceptions.py
class NotInitialisedError(WrapperError):
    """
    Raised when the wrapper around the Fortran module hasn't been initialised yet
    """

    def __init__(self, instance: Any, method: Optional[Callable[..., Any]] = None):
        if method:
            error_msg = f"{instance} must be initialised before {method} is called"
        else:
            error_msg = f"instance ({instance:r}) is not initialised yet"

        super().__init__(error_msg)

UnallocatedMemoryError #

Bases: ValueError

Raised when we try to access memory that has not yet been allocated

We can't always catch this error, but this is what we raise when we can.

Source code in src/example_fgen_basic/pyfgen_runtime/exceptions.py
class UnallocatedMemoryError(ValueError):
    """
    Raised when we try to access memory that has not yet been allocated

    We can't always catch this error, but this is what we raise when we can.
    """

    def __init__(self, variable_name: str):
        error_msg = (
            f"The memory required to access `{variable_name}` is unallocated. "
            "You must allocate it before trying to access its value. "
            "Unfortunately, we cannot provide more information "
            "about why this memory is not yet allocated."
        )

        super().__init__(error_msg)

WrapperError #

Bases: ValueError

Base exception for errors that arise from wrapper functionality

Source code in src/example_fgen_basic/pyfgen_runtime/exceptions.py
class WrapperError(ValueError):
    """
    Base exception for errors that arise from wrapper functionality
    """