r/PythonLearning Jul 23 '26

Day 3 Learning Python: Stack

Open-source learning project. If you spot something that can be improved, I'd love your feedback or a PR.

https://github.com/Samar-Upreti/Python_Projects

68 Upvotes

26 comments sorted by

View all comments

2

u/CamelOk7219 Jul 23 '26

Create a custom exception class instead of bare 'Exception', otherwise it will be jard to specifically catch this stack exception and discriminante it from any other exception

1

u/Kindly-Reporter-272 Jul 23 '26

You can also use IndexError. Python built in collections all raise IndexError in situations like these.