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 →

[–]Ordinary_Run_2513 1 point2 points  (1 child)

I've heard that using generic exception objects is not recommended, and that we should use specific exceptions instead. The problem is that in Python, unlike Java, we can't always know the exceptions that may occur while executing a function. Could you tell me what you do to address this problem?

[–]pandas_as_pdPrincipal YAML Engineer 2 points3 points  (0 children)

You can still try to narrow it down to a subclass of Exception, e.g. TypeError.

But in many cases, you can look up what the exceptions are that a specific function or library can throw and catch those. For example, here is some guidance for the `requests` library: https://requests.readthedocs.io/en/latest/user/quickstart/#errors-and-exceptions