Closed wmwv closed 7 months ago
That sounds like a great idea! Let me know if there are any particular cases you would like to catch. Otherwise I'll just start by replacing the assert
statements and other raises
and go from there.
Closed by #137
Is your feature request related to a problem? Please describe. I'm surprised to see and get
AssertionError
generated byassert
statements.Describe the solution you'd like I would expect infomative Errors to be raised. This seems more Pythonic to me.
I might suggest creating a informative hierarchy of Errors to raise. That will allow a user to catch errors they want and can deal with, and let others continue on to raise.
I just spent 10 minutes failing to find a good example that wasn't just search-bait fluff. But here's the official documentation along with an example that uses custom exceptions the way I'm thinking; basically it's as simple as creating a class with a name -- and it's that name that's going to be informative about what type of error was raised and whether or not you want to do anything about it.
https://docs.python.org/3/library/exceptions.html#exception-hierarchy https://breadcrumbscollector.tech/custom-exceptions-in-python-how-and-what-for/
This one's kind of okay too, just note that it explicitly
raise
s the exceptions in thetry
part of the examples, where in a real application it would be some operation that should have worked that would be in thetry
block and theexcept
block would just choose to deal with selected errors (and ignore other ones).https://www.geeksforgeeks.org/user-defined-exceptions-python-examples/#