How to Re-raise an Exception in Python with raise
Sometimes a piece of code needs to react to an error, such as logging it or undoing a change, without being the place that decides what happens next. A bare raise inside except sends the same exception on, with its original traceback, after your code has run. This guide shows it with a small number parser, with real output from Python 3.15.2.
Syntax
try:
<code that may fail>
except <ExceptionType>:
<what to do first>
raise
| Part | What it means |
|---|---|
except <ExceptionType>: | Catches the error so your code runs first |
raise with nothing after it | Raises the same exception again, unchanged |
Python's language reference: "If no expressions are present, raise re-raises the exception that is currently being handled, which is also known as the active exception. If there isn't currently an active exception, a RuntimeError exception is raised indicating that this is an error."
Prerequisites
- uv and Python. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with
uv init.
Step 1: Write the Script
def read_age(text):
try:
return int(text)
except ValueError:
print(f"Logging: can't read {text} as a number")
raise
print(read_age("42"))
print(read_age("forty"))

Step 2: Run It
uv run python read_age.py
42
Logging: can't read forty as a number
Traceback (most recent call last):
File "/Users/you/source/python-basics/read_age.py", line 10, in <module>
print(read_age("forty"))
~~~~~~~~^^^^^^^^^
File "/Users/you/source/python-basics/read_age.py", line 3, in read_age
return int(text)
ValueError: invalid literal for int() with base 10: 'forty'

The log line printed first, then the original ValueError carried on, and its traceback still points at return int(text) on line 3, where it began. The caller decides what to do with it; here nobody catches it, so the script stops.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Using a bare raise outside an except block | RuntimeError: No active exception to reraise | Use it only while an exception is being handled |
| Catching an error, logging it and not re-raising | The caller never learns that something failed | Re-raise unless your code truly handled it |
| Raising a new exception that hides the original | The real cause disappears from the traceback | Use a bare raise, or raise NewError(...) from error |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The same error is logged twice | Two layers each log, then re-raise | Log in one place only, usually the outermost |
FAQ
What's the difference between raise and raise error?
After except ValueError as error:, both raise the same exception object. The bare form needs no name and says plainly that the exception continues unchanged.
Can I add information before re-raising?
Yes. Since Python 3.11, error.add_note("...") adds a line to the traceback before you raise.
Conclusion
Inside except ValueError, the parser printed its log line and the bare raise sent the original ValueError on, with its traceback still pointing at int(text).
Additional Resources
- The raise statement — re-raising the active exception.
