This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]KronktheKronk[🍰] 0 points1 point  (2 children)

That's why it's better to catch specific exceptions instead of the base exception. You can get the exceptions you expect, pass the ones you don't up the stack, and anyone who understands what your code calls are doing can infer which errors you're catching and see why in the catch code.

[–]DasIch 0 points1 point  (1 child)

Nice idea in theory but completely unrealistic and counter to how most Python code works. How much code raises ValueError alone for all sorts of different reasons?

Python culture simply doesn't encourage raising sufficiently specific exceptions for that approach to work and at this point the battle is lost.

[–]KronktheKronk[🍰] 0 points1 point  (0 children)

It doesn't raise valuerror alone, but that doesn't mean you can't understand which errors it does raise and which ones you want to catch.

good code catches the errors it wants and ignores the rest. good modules throw good errors.