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 | list[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 | list[int] | slice
        The wrongly used index.
    """

    def __init__(self, index: int | list[int] | slice):
        if isinstance(index, list):
            if len(index) == 1:
                index = index[0]
            else:
                super().__init__(f"There are no elements at indices {index}.")
                return
        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 | list[int] | slice):
    if isinstance(index, list):
        if len(index) == 1:
            index = index[0]
        else:
            super().__init__(f"There are no elements at indices {index}.")
            return
    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}].")