Status: Accepted
Owner: asmeurer
Labels: Type-Defect Priority-Medium
New issue 2570 by asmeurer: Remove bare except statements
http://code.google.com/p/sympy/issues/detail?id=2570
If you do git grep "except:" you will see that there are several places in
the code with bare except statements that should be rewritten to catch
explicit exceptions. To quote the Zen of Python:
Errors should never pass silently.
Unless explicitly silenced.
And to quite PEP 8:
- When catching exceptions, mention specific exceptions
whenever possible instead of using a bare 'except:' clause.
For example, use:
try:
import platform_specific_module
except ImportError:
platform_specific_module = None
A bare 'except:' clause will catch SystemExit and KeyboardInterrupt
exceptions, making it harder to interrupt a program with Control-C,
and can disguise other problems. If you want to catch all
exceptions that signal program errors, use 'except Exception:'.
A good rule of thumb is to limit use of bare 'except' clauses to two
cases:
1) If the exception handler will be printing out or logging
the traceback; at least the user will be aware that an
error has occurred.
2) If the code needs to do some cleanup work, but then lets
the exception propagate upwards with 'raise'.
'try...finally' is a better way to handle this case.
To be sure, some of the bare except cases in the code are correct by the
above (like the ones in the test runner), but many are not.
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy-issues?hl=en.