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

    76 From Python documentation -> 8.3 Handling Exceptions: A try statement may have more than one except clause, to specify handlers for different exceptions. At most one handler will be executed. …

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

  3. python - When I catch an exception, how do I get the type, file, and ...

    56 Source (Py v2.7.3) for traceback.format_exception () and called/related functions helps greatly. Embarrassingly, I always forget to Read the Source. I only did so for this after searching for similar …

  4. python exception handling - Stack Overflow

    Jan 4, 2011 · import logging logging.basicConfig(level=logging.DEBUG) logging.debug('This message should go to the log file') try: 1/0 except Exception as e: logging.exception(e) This example uses the …

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

    How do I declare custom exception classes in modern Python? My primary goal is to follow whatever standard other exception classes have, so that (for instance) any extra string I include in the …

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

    I can't figure out how to handle exception for python 'with' statement. If I have a code:

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

  8. python - Catch a thread's exception in the caller thread ... - Stack ...

    Mar 28, 2022 · t.join() And you'll see the exception raised on the other thread when you join. If you are using six or on Python 3 only, you can improve the stack trace information you get when the …

  9. Why do we need the "finally" clause in Python? - Stack Overflow

    Feb 7, 2017 · Also, it won't be cleaned up if execution never reaches the try block. (i.e. create_resource itself throws an exception) It makes your code "exception safe". As to why you actually need a finally …

  10. Python global exception handling - Stack Overflow

    Jul 6, 2011 · Python global exception handling Asked 14 years, 5 months ago Modified 1 year, 3 months ago Viewed 62k times