About 50,000 results
Open links in new tab
  1. python - How can I catch multiple exceptions in one line? (in the ...

    As of Python 3.11 you can take advantage of the except* clause that is used to handle multiple exceptions. PEP-654 introduced a new standard exception type called ExceptionGroup that …

  2. Catching an exception while using a Python 'with' statement

    The best way to handle exceptions in python is to write a function that catches and returns them? Seriously? The pythonic way to handle exceptions is to use a try...except statement.

  3. python - How can I write a `try`/`except` block that catches all ...

    In Python, all exceptions must be instances of a class that derives from BaseException, but if you can omit it for a general case - omit it, problem is, linters wine about it.

  4. What is a good way to handle exceptions when trying to read a …

    What is a good way to handle exceptions when trying to read a file in python? Asked 14 years, 7 months ago Modified 6 months ago Viewed 381k times

  5. How do I declare custom exceptions in modern Python?

    By "modern Python" I mean something that will run in Python 2.5 but be 'correct' for the Python 2.6 and Python 3.* way of doing things. And by "custom" I mean an Exception object that can …

  6. Best Practices for Python Exceptions? - Stack Overflow

    Robust exception handling (in Python) - a "best practices for Python exceptions" blog post I wrote a while ago. You may find it useful. Some key points from the blog: Never use exceptions for …

  7. Logging uncaught exceptions in Python - Stack Overflow

    Ignore KeyboardInterrupt so a console python program can exit with Ctrl + C. Rely entirely on python's logging module for formatting the exception. Use a custom logger with an example …

  8. python - How to handle unhandled exceptions? - Stack Overflow

    May 7, 2013 · I'm cleaning up an API library, and trying to figure out the best way to handle unhandled exceptions. Right now, the library catches just about everything that could go …

  9. Correct way to try/except using Python requests module?

    Aug 21, 2022 · except requests.exceptions.RequestException as e: # This is the correct syntax raise SystemExit(e) Or you can catch them separately and do different things.

  10. Correct way of handling exceptions in Python? - Stack Overflow

    Aug 17, 2009 · If each line of your program can throw several different exceptions, and each needs to be handled individually, then the bulk of your code is going to be exception handling. …