About 50 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 …

  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 …

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

  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. python - When I catch an exception, how do I get the type, file, …

    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 …

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

  7. python exception handling - Stack Overflow

    Jan 4, 2011 · There are various ways to format the exception, the logging module (which I assume you/Django uses) has support to format exceptions, and the exceptions themselves …

  8. Manually raising (throwing) an exception in Python

    How do I raise an exception in Python so that it can later be caught via an except block?

  9. python - How to retry after exception? - Stack Overflow

    @g33kz0r the for-else construct in Python executes the else clause if the for loop doesn't break. So, in this case, that section executes if we try all 10 attempts and always get an exception.

  10. exception - What is the intended use of the optional "else" clause …

    From Errors and Exceptions # Handling exceptions - docs.python.org The try ... except statement has an optional else clause, which, when present, must follow all except clauses.