how to abort on syntax errors

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Mar 26 14:07:42 EDT 2007


En Mon, 26 Mar 2007 14:21:22 -0300, Josh <noone at nowhere.com> escribió:

> I have a lot of except Exception, e statements in my code, which poses  
> some
> problems.

*many* problems, I'd say. Don't do that :)

> One of the biggest is whenever I refactor even the triviallest
> thing in my code.
>
> I would like python to abort, almost as if it were a compile-time error,
> whenever it cannot find a function, or if I introduced a syntax error.  
> But,
> instead, it merrily proceeds on its way.

Because you have told Python to do so, using a catch-all except clause.  
Try to be as specific as possible.
Syntax errors, indentation errors and such can be caught just by compiling  
the module, even before you try to test it.

> Is there some idiom that you use in situations like these?

Avoid bare except clauses as much as you can.

-- 
Gabriel Genellina




More information about the Python-list mailing list