About 6,130,000 results
Open links in new tab
  1. How do I declare custom exceptions in modern Python?

    By "modern Python" I mean something that will run in Python 2.5 but be 'correct' for the Python 2.6 and Python 3.* way of doing things. And by "custom" I mean an Exception object that can …

  2. 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?

  3. Catching an exception while using a Python 'with' statement

    The best way to handle exceptions in python is to write a function that catches and returns them? Seriously? The pythonic way to handle exceptions is to use a try...except statement.

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

    In Python, all exceptions must be instances of a class that derives from BaseException, but if you can omit it for a general case - omit it, problem is, linters wine about it.

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

    144 Python 3: logging Instead of using the basic print() function, the more flexible logging module can be used to log the exception. The logging module offers a lot extra functionality, for …

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

    Feb 22, 2009 · 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 …

  7. How to get exception message in Python properly

    Oct 20, 2015 · What is the best way to get exceptions' messages from components of standard library in Python? I noticed that in some cases you can get it via message field like this: try: …

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

    I want to read a .csv file in python. I don't know if the file exists. My current solution is below. It feels sloppy to me because the two separate exception tests are awkwardly juxtaposed. Is th...

  9. Catch and print full Python exception traceback without …

    I want to catch and log exceptions without exiting, e.g., try: do_stuff () except Exception as err: print (Exception, err) # I want to print the entire traceback here, # not just the

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