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

    At most one handler will be executed. Handlers only handle exceptions that occur in the corresponding try clause, not in other handlers of the same try statement. An except clause …

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

  3. python - Multiple try codes in one block - Stack Overflow

    Jun 26, 2013 · try: code a except ExplicitException: pass try: code b except ExplicitException: pass try: code c except ExplicitException: pass try: code d except ExplicitException: pass I'm …

  4. python - How to handle multiple exceptions? - Stack Overflow

    Aug 10, 2016 · However, sometimes it is appropriate to catch different types of exceptions, in the same except block or in several blocks. try: ssh.connect() except (ConnectionRefused, …

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

    Feb 14, 2011 · I very very strongly disagree with the statement, "shouldn't." You should do it sparingly. There are times when you're dealing with third party libraries (sometimes …

  6. How to write multiple try statements in one block in python?

    Dec 14, 2012 · If all functions throw exceptions, return `default` Args: flist - list of functions to try default - value to return if all functions fail Returns: return value of first function that does not …

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

    Jun 10, 2013 · A good and simple example for nested try/except could be the following: import numpy as np def divide(x, y): try: out = x/y except: try: out = np.inf * x / abs(x) except: out = …

  8. writing multiple try and except in python - Stack Overflow

    Dec 29, 2015 · The pattern seems to be that you're trying several operations on each line (some kind of pattern matching?) and if there's an exception it's just swallowed anyway. Maybe use …

  9. Python: Multiple try except blocks in one? - Stack Overflow

    Multiple statements in a try clause is an anti-pattern and bad form. The information is available in a stack trace, but a stack trace is not always available. The best practice is to understand …

  10. How to catch multiple exceptions at once and deal with individual …

    Jul 20, 2020 · I understand you can do multiple exceptions handling in this way. try: pass except EOFError: deals_with_EOFError() except FileNotFoundError: deals_with_FileNotFoundError() …