About 250,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. Are nested try/except blocks in Python a good programming …

    Jun 10, 2013 · If try-except-finally is nested inside a finally block, the result from "child" finally is preserved. I have not found an official explanation yet, but the following code snippet shows …

  3. Is it a good practice to use try-except-else in Python?

    Apr 22, 2013 · Even the Python core developers use exceptions for flow-control and that style is heavily baked into the language (i.e. the iterator protocol uses StopIteration to signal loop …

  4. How to work with try and except in python? - Stack Overflow

    May 28, 2020 · The Exception class is the superclass of every single built-in exception in the Python environment that are non-system-exiting (read here) and its generally a bad practice to …

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

    In Python, is it possible to have multiple except statements for one try statement? Such as: try: #something1 #something2 except ExceptionType1: #return xyz except ExceptionType2: #...

  6. How do I print an exception in Python? - Stack Overflow

    I would recommend using a try-except statement. Also, rather than using a print statement, a logging exception logs a message with level ERROR on the logger, which I find is more …

  7. What is the intended use of the optional "else" clause of the "try ...

    The Python Tutorial elaborates on the intended usage: The try ... except statement has an optional else clause, which, when present, must follow all except clauses. It is useful for code …

  8. python - Difference between except: and except Exception as e:

    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?

  9. python - How to properly ignore exceptions - Stack Overflow

    When you just want to do a try-except without handling the exception, how do you do it in Python? Is the following the right way to do it? try: shutil.rmtree(path) except: pass

  10. Catch exception and continue try block in Python

    29 You can achieve what you want, but with a different syntax. You can use a "finally" block after the try/except. Doing this way, python will execute the block of code regardless the exception …