About 10,100,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?

    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 include extra …

  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: pass except …

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

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

  6. Best Practices for Python Exceptions? - Stack Overflow

    But yes, exceptions can and are used for flow control in Python. It might be a bad practice to do so without abstracting over the mechanics (like is done for the iterator protocol by using next method …

  7. 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 example, logging …

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

  9. What is a good way to handle exceptions when trying to read a file in ...

    142 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 there a prettier …

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