# Reading a Python traceback from the bottom up

Published: 2026-11-30

Rights: original
Source: https://kairos-2z6s.onrender.com/res/python-traceback-full-en
A Python exception stops the program and prints a traceback to standard error; the process exits with status 1. TE-21-A shows the exit status and the last traceback line. TE-21-B shows a caught exception, which exits with status 0.

Each command below is the exact command that was run and each output block is copied from the recorded log. Test ids, log hashes and exit statuses are in the evidence table.

(Test: 3 tests were run, TE-21-A, TE-21-B and TE-21-C. The expected non-zero exit is TE-21-C (exit status 1). Every row has a recorded log in the evidence archive. The evidence table lists the exit status and log hash of every row, and no Exit status line on this page is for the A row.)

### TE-21-A: an uncaught exception exits 1 and the last traceback line carries the exception type and message

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
printf 'def f():\n    return int("x")\nf()\n' > s.py
```

The file written as `../name` sits one level above the working folder, inside the same throwaway tree.

Command:

```bash
python3 s.py 2>../tb.err; echo exit=$?; tail -1 ../tb.err
```

Recorded output:

```
exit=1
ValueError: invalid literal for int() with base 10: 'x'
```

### TE-21-B: a caught exception does not stop the program: the script prints a message and exits with status 0

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
printf 'try:\n    int("x")\nexcept ValueError:\n    print("caught")\n' > s.py
```

Command:

```bash
python3 s.py; echo exit=$?
```

Recorded output:

```
caught
exit=0
```

Exit status: 0. This status and the output match what was written before the run.

### TE-21-C: expected non-zero exit: an uncaught ZeroDivisionError exits with status 1 and the last traceback line names the error

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
printf 'print(1 / 0)\n' > s.py
```

Paths written as `../name` sit one level above the working folder, inside the same throwaway tree.

Command:

```bash
python3 s.py 2>../tb.err; rc=$?; tail -1 ../tb.err; exit $rc
```

Recorded output:

```
ZeroDivisionError: division by zero
```

Exit status: 1. This status and the output match what was written before the run.

## Reading the recorded output

The program calls f(), which calls int with the text x. The line exit=1 is the exit status of the Python process. The last line of the traceback, copied by tail -1, names the exception type, ValueError, and then the message, which includes the text that could not be converted, 'x'. The run keeps only that last line, so the lines above it, which list the call path, are not shown.

TE-21-B: the exception was caught, so caught was printed and exit=0 shows status 0. TE-21-C: the traceback went to ../tb.err. Its last line is ZeroDivisionError: division by zero, and the script exited with status 1.

## Limits

TE-21-A shows only the exit status and the last traceback line, which holds the exception type and message. The call path lines above it are not shown here.

## Source

- https://docs.python.org/3/tutorial/errors.html

## Evidence

- `TE-21-A`: an uncaught exception exits 1 and the last traceback line carries the exception type and message

- logs: one recorded log for each row above
- Recorded on: Linux x86_64, kernel 7.3.4; bash 5.1.16; git 2.34.1; python 3.10.12; findutils 4.8.0; grep 3.7; sed 4.8; gawk 5.1.0; tar 1.34; curl 7.81.0. Locale C.UTF-8, TZ=UTC.

## Evidence table

| Test | What it checks | Exit | Verdict | Log sha256 (first 12) |
|---|---|---|---|---|
| `TE-21-A` | an uncaught exception exits 1 and the last traceback line carries the exception type and message | 0 | PASS | `8c0969da78a3` |
| `TE-21-B` | a caught exception does not stop the program: the script prints a message and exits with status 0 | 0 | PASS | `a02cbab7c06c` |
| `TE-21-C` | expected non-zero exit: an uncaught ZeroDivisionError exits with status 1 and the last traceback line names the error | 1 | PASS | `afb4a3cf95f2` |

Every row has a recorded log holding the setup commands, the command, stdout, stderr, exit status and the final directory state. The first 12 characters of the log's sha256 are in the table.

## Related guides
- [python -m venv: a separate package folder for one project](https://kairos-2z6s.onrender.com/res/python-venv-full-en)
- [Python sys.exit: set the exit status](https://kairos-2z6s.onrender.com/res/python-sys-exit-full-en)
- [Python try and except: handle an error on purpose](https://kairos-2z6s.onrender.com/res/python-try-except-full-en)
- [Python try and finally: code that always runs](https://kairos-2z6s.onrender.com/res/python-try-finally-full-en)
- [Python With Statement: files closed for you](https://kairos-2z6s.onrender.com/res/python-with-statement-full-en)
