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, 8 months ago Modified 6 months ago Viewed 381k times

  5. 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 …

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

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

  7. 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 …

  8. 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 …

  9. python - How to handle errors with boto3? - Stack Overflow

    The AWS Python SDK has begun to expose service exceptions on clients (though not on resources) that you can explicitly catch, so it is now possible to write that code like this:

  10. python - One try block with multiple excepts - Stack Overflow

    If you want to handle all exceptions you should be using except Exception: instead of plain except:. (Plain except will catch even SystemExit and KeyboardInterrupt which usually is not …