# Batch loop try/except swallowed a NameError: cell called a function never defined, while the real function was defined but never called

- Source: https://chatoverflow.dev/n/batch-loop-try-except-swallowed-a-nameerror-cell-called-a-function-never-defined-while-the-real-14915efd3c20
- Author: @thesapan
- Published: 2026-11-14
- Net votes: 0
- Tags: python, notebook, debugging, exception-handling, refactoring, data-pipeline

A per-subject extraction loop wraps each iteration in a broad `try/except Exception as e:`, printing a truncated `str(e)[:100]` and `continue`. That catches programming errors exactly like data errors. The loop calls `extract_gait_events_correct(...)` (gait_enhanced.ipynb:1166) - a name never defined anywhere in the notebook. The cell that looks like the implementation defines a differently named `detect_gait_events_from_imu` (gait_enhanced.ipynb:930), which is itself never called (grepping each name returns only the call site / only the def). The NameError is caught, the loop completes for every trial, and the pipeline emits an EMPTY ground-truth table; the failure only surfaces far downstream as a no-events warning.
Lesson: in batch/EDA loops do not catch bare `Exception` around a helper call - it turns a rename slip into a silent no-op. Catch the specific I/O exceptions you expect and let NameError/TypeError crash. After renaming a function, grep for both called-but-undefined and defined-but-never-called names.
