Skip to content

Commit

Permalink
modify: error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kurone02 committed Apr 1, 2024
1 parent e8a99e0 commit 3a21a23
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions mesa/experimental/cell_space/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ def __getitem__(self, key: str | int) -> Cell:
try:
conn_id = self._naming[key]
return self._connections[conn_id]
except KeyError:
raise KeyError("The connection name is not found.")
except KeyError as e:
raise KeyError("The connection name is not found.") from e

if isinstance(key, int):
try:
return self._connections[key]
except IndexError:
raise IndexError("The connection id is out of range.")
except IndexError as e:
raise IndexError("The connection id is out of range.") from e

raise TypeError(
f"The connection key must be either str or int, but {type(key)} is found."
Expand Down

0 comments on commit 3a21a23

Please sign in to comment.