[Python-ideas] Consistent programming error handling idiom
steve at pearwood.info
Fri Apr 8 15:01:19 EDT 2016
On Sat, Apr 09, 2016 at 04:28:47AM +1000, Chris Angelico wrote:
> ANY uncaught exception is a bug.
What, even SystemExit and KeyboardInterrupt?
> Any caught exception is not a bug.
# Look, bug free programming!
I am sure that any attempt to make universal rules about what is or
isn't a bug will be doomed to failure. Remember that people can write
code like this:
# Writing a BASIC interpreter in Python.
if not isinstance(command, int):
raise SyntaxError('expected line number')
So, no, SyntaxError does not necessarily mean a bug in your code. *ALL*
exceptions have to be understood in context, you can't just make a
sweeping generalisation that exception A is always a bug, exception B is
always recoverable. It depends on the context.
More information about the Python-ideas