Replace bare except with except Exception in execution.py by harshadkhetpal · Pull Request #5663 · aws/sagemaker-python-sdk
Summary
This PR replaces bare except: clauses with except Exception: in sagemaker-train/src/sagemaker/train/evaluate/execution.py.
Bare except: catches all exceptions including SystemExit, KeyboardInterrupt, and GeneratorExit, which are typically not intended to be caught. Using except Exception: is the recommended practice as it only catches regular exceptions while allowing system-level exceptions to propagate normally.
Changes
- Line 907:
except:→except Exception:(IPython import fallback) - Line 961:
except:→except Exception:(datetime parsing fallback)
Testing
This is a safe behavioral improvement — except Exception: covers all the same cases these handlers intend to catch (ImportError, ValueError, etc.) without accidentally suppressing KeyboardInterrupt or SystemExit.