About 135,000 results
Open links in new tab
  1. Is it a good practice to use try-except-else in Python?

    Apr 22, 2013 · In the Python world, using exceptions for flow control is common and normal. -- I think it's worth drawing a distinction between "the Python world" and "the CPython core devs …

  2. Are nested try/except blocks in Python a good programming …

    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 this behavior in …

  3. Using 'try' vs. 'if' in Python - Stack Overflow

    It's perfectly OK (and "pythonic") to use try/except for flow control, but it makes sense most when Exception s are actually exceptional. From the Python docs: EAFP Easier to ask for …

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

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

    Dive into python has an example where, if I understand correctly, in try block they try to import a module, when that fails you get exception and bind default but when it works you have an …

  6. 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: #...

  7. python - How can I write a `try`/`except` block that catches all ...

    @CharlieParker you could try except BaseException as e: notify_user(e); raise that would catch all exceptions and do whatever notification you need, but I don't know HPC so you might want …

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

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

  10. What is a good way to handle exceptions when trying to read a …

    The answers to this question should probably be updated to include usage of the pathlib module, which makes this problem a lot easier, and should probably be standard Python practice …