About 383,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. 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.

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

  8. python - How to handle FileNotFoundError when "try .. except IOError ...

    Possible duplicate of Python's "open ()" throws different errors for "file not found" - how to handle both exceptions?

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

  10. python - Difference between except: and except Exception as e: - Stack ...

    Apr 6, 2021 · try: #some code that may throw an exception except Exception as e: #exception handling code What is exactly the difference in both the constructs?