About 54,700 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 raise the same Exception with a custom message in Python?

    Feb 6, 2012 · File "test.py", line 4, in <module> raise Exception('Smelly socks') from e Exception: Smelly socks Notice the bottom exception only has the stacktrace from where we raised our exception. Your …

  3. Python "raise from" usage - Stack Overflow

    In other words, Python sets a context on exceptions so you can introspect where an exception was raised, letting you see if another exception was replaced by it.

  4. How to use "raise" keyword in Python - Stack Overflow

    Besides raise Exception("message") and raise Python 3 introduced a new form, raise Exception("message") from e. It's called exception chaining, it allows you to preserve the original …

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

  6. What is the proper way to raise an exception in Python?

    Oct 24, 2012 · if len(sys.argv) == 1: raise EmptyArgs('Specify at least 1 argument') See the documentation for the raise statement Python 2 had a few more options, these have been dropped …

  7. python - What's the difference between raise, try, and assert? - Stack ...

    Where as try, raise and except makeup exception handling which is the preferred way in python to handle and propagate errors. Most libraries and the python built-ins will raise and Exception of one …

  8. python - How to re-raise an exception in nested try/except blocks ...

    Aug 12, 2013 · 206 I know that if I want to re-raise an exception, I simple use raise without arguments in the respective except block. But given a nested expression like

  9. python - Define a lambda expression that raises an Exception - Stack ...

    Nov 28, 2011 · Alternatively you can raise an exception without defining a named function. All you need is a strong stomach (and 2.x for the given code):

  10. python - How to raise an Exception and still continue the main code ...

    Dec 21, 2017 · Without using the try/catch it is not possible in python. When we call a function in python and it raises a exception, the exceptions is propagated to the caller function and it continues.