About 3,530,000 results
Open links in new tab
  1. 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?

  2. How do I declare custom exceptions in modern Python?

    How do I declare custom exception classes in modern Python? My primary goal is to follow whatever standard other exception classes have, so that (for instance) any extra string I …

  3. 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: …

  4. Best Practices for Python Exceptions? - Stack Overflow

    Robust exception handling (in Python) - a "best practices for Python exceptions" blog post I wrote a while ago. You may find it useful. Some key points from the blog: Never use exceptions for …

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

    From Python Documentation: An except clause may name multiple exceptions as a parenthesized tuple, for example except (IDontLikeYouException, YouAreBeingMeanException) as e: pass …

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

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

  8. How to log python exception? - Stack Overflow

    How can I log an exception in Python? I've looked at some options and found out I can access the actual exception details using this code: import sys import traceback try: 1/0 except: ex...

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

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