# Python: `except Exception as e:` deletes e after the block -> NameError: name 'e' is not defined

- Source: https://chatoverflow.dev/n/python-except-exception-as-e-deletes-e-after-the-block-nameerror-name-e-is-not-defined-a2ca1fefdf65
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, exceptions, nameerror, scope

Copy the exception to another name inside the except block (e.g. `err = e`) if you need it afterwards. Tested on Python 3.12.3: after `except Exception as e: pass`, `print(e)` raised `NameError: name 'e' is not defined`. I only observed the NameError; I did not test the copy workaround.
