About 3,870,000 results
Open links in new tab
  1. Catch exception and continue try block in Python

    Doing this way, python will execute the block of code regardless the exception was thrown, or not. Like this: try: do_smth1() except: pass finally: do_smth2()

  2. exception - Catch any error in Python - Stack Overflow

    Jul 25, 2011 · In an interactive session this happens just before control is returned to the prompt; in a Python program this happens just before the program exits. The handling of such top-level exceptions can be customized by assigning another three-argument function to sys.excepthook.

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

    Technically, it should catch all non-system-exiting exceptions. From the docs @DDay linked: "exception BaseException: The base class for all built-in exceptions.

  4. Python: How to ignore an exception and proceed? [duplicate]

    Feb 22, 2009 · Python 3. In Python 3, the variable that holds the exception instance gets deleted on exiting the except block. Even if the variable held a value previously, after entering and exiting the except block it becomes undefined again.

  5. python - How can I catch multiple exceptions in one line? (in the ...

    This usage, the only form available in Python 2.5 and earlier, is deprecated, and if you wish your code to be forward compatible in Python 3, you should update the syntax to use the new form: import sys try: mainstuff() except (KeyboardInterrupt, EOFError), err: # don't do this in Python 2.6+ print err print err.args sys.exit(0)

  6. python - Handle JSON Decode Error when nothing returned

    There is a rule in Python programming called "it is Easier to Ask for Forgiveness than for Permission" (in short: EAFP). It means that you should catch exceptions instead of checking values for validity. Thus, try the following:

  7. Correct way to try/except using Python requests module?

    Aug 21, 2022 · You'll only catch connection-related errors, not ones that time out. What to do when you catch the exception is really up to the design of your script/program. Is it acceptable to exit?

  8. Manually raising (throwing) an exception in Python

    Jun 13, 2022 · To catch it, you'll have to catch all other more specific exceptions that subclass it. Problem 1: Hiding bugs raise Exception('I know Python!') # Don't! If you catch, likely to hide bugs. For example:

  9. How to log python exception? - Stack Overflow

    May 8, 2017 · The first argument to logging.exception isn't for the exception to log (Python just grabs the one from the current except: block by magic), it's for the message to log before the traceback. Specifying the exception as the message causes it to be converted to a string, which results in the exception message being duplicated.

  10. How to get exception message in Python properly

    Oct 20, 2015 · If you narrow the exceptions that except will catch to a subset, you should be able to determine how they were constructed, and thus which argument contains the message. try: # do something that may raise an AuthException except AuthException as ex: if ex.args[0] == "Authentication Timeout.": # handle timeout else: # generic handling

  11. Some results have been removed
Refresh