[IPython-dev] [Ipython-svndiff] 2717 - improve callable alias inspection
fperez.net at gmail.com
Thu Sep 6 02:32:26 EDT 2007
On 9/6/07, Gael Varoquaux <gael.varoquaux at normalesup.org> wrote:
> On Thu, Sep 06, 2007 at 12:06:43AM -0600, Fernando Perez wrote:
> > Hey,
> > On 9/5/07, ipython-svndiff at scipy.org <ipython-svndiff at scipy.org> wrote:
> > > + try:
> > > + ds = "Alias to the system command:\n %s" % obj
> > > + except:
> > > + ds = "Alias: " + str(obj)
> > What is this bare 'except' clause trying to stop? Is it the
> > IndexError from obj or a possible error on str()? Catch-all naked
> > excepts should really be avoided except for a few occasions where they
> > are there as last-resort measures to prevent a full crash. They tend
> > to mask the real intent of the code and hide possible unintended bugs.
> That's interesting. Yesterday we were discussing with colleagues whether
> to add an except statement in a bit of code we were adding to a large
> Matlab framework (10K lines ore more). We didn't want that bit of code,
> which was controlling an external instrument, to bring down the whole
> experiment if communication was lost with the instrument.
> However Matlab as no exception hierarchy that we know of, and no
> "finally" clause, so we decided against the except, preferring to bring
> down the experiment than to have a problem we could not diagnose.
IPython does need bare excepts in quite a few places in order to
shield the user's session from errors thrown by random errors, but
sometimes that makes debugging very hard, since many of those pass
silently (exceptions in tab completion, for example).
Here's an idea that might help with this. We could define a special
DebugException as follows:
class CatchAllException(Exception): pass
# normal mode
CatchAllException = Exception
Then, all code that needs to have very wide-ranging excepts can be written as:
handle what you know what to do with...
# in normal mode
print 'Normally suppressed traceback shown:'
Since this exception wouldn't be actually ever thrown by anyone, when
in Debug mode the second 'except' would become effectively inactive,
turning the third one on for debugging.
More information about the IPython-dev