Skip to content

IndexOutOfBoundsError

Bases: IndexError

Exception raised for trying to access an element by an index that does not exist in the underlying data.

Parameters:

Name Type Description Default
index int | slice

The wrongly used index.

required
Source code in src/safeds/exceptions/_data.py
class IndexOutOfBoundsError(IndexError):
    """
    Exception raised for trying to access an element by an index that does not exist in the underlying data.

    Parameters
    ----------
    index : int | slice
        The wrongly used index.
    """

    def __init__(self, index: int | slice):
        if isinstance(index, int):
            super().__init__(f"There is no element at index '{index}'.")
        else:
            super().__init__(f"There is no element in the range [{index.start}, {index.stop}]")

__init__(index)

Source code in src/safeds/exceptions/_data.py
def __init__(self, index: int | slice):
    if isinstance(index, int):
        super().__init__(f"There is no element at index '{index}'.")
    else:
        super().__init__(f"There is no element in the range [{index.start}, {index.stop}]")