replace bare except: with specific exception types#167
Conversation
|
It is a while back for me, but I these exceptions were there to make sure the whole program does not fall down if e.g. it encounters a NAN or inf, or some other unexpected insert in one of the voxels. But I agree that the program should break if there is something fundamentally wrong. Are we sure these are the only exceptions we want to catch to ensure stable behaviour? |
Replace all 13 bare except: blocks in LSQ_fitting.py and 1 in triexp_fitting_algorithms.py with specific exception types: - Parallel fallbacks: except Exception - curve_fit/minimize failures: except (RuntimeError, ValueError) - Bayesian fit: except (RuntimeError, ValueError, TypeError) - Goodness-of-fit: except (IndexError, ValueError) - NNLS: except Exception Also fix pre-existing bug: raise(params.message) on line 668 was raising a string (TypeError), not an exception. Changed to raise RuntimeError(params.message). Fixes Bug OSIPI#3 from bugs.md
f86e0ce to
8a3df31
Compare
|
Hello @oliverchampion sir, i apologise for the delay, i was busy finding an internship. I got the time now and reviewed what you said. You were right, i did miss some exceptions. To find everything i wrote a sanity-check script that feeds nan, inf, zeros, huge values, negative signals, and other edge cases into every function. Result was 53/53 bad-data scenarios handled gracefully (no crashes). |
Replace all 13 bare except: blocks in LSQ_fitting.py and 1 in triexp_fitting_algorithms.py with specific exception types:
Also fix pre-existing bug: raise(params.message) on line 668 was raising a string (TypeError), not an exception. Changed to raise RuntimeError(params.message).
Fixes #166