[wingide-users] Stop on exception, within try block?
gadgetsteve at hotmail.com
Tue Feb 25 15:24:08 EST 2014
On 25/02/14 00:37, Graham Wideman wrote:
> [Arrrg, resubmitted due to wrong from address.]
> Hi folks,
> Apologies if I've overlooked something obvious, but:
> Is there a setting, feature or approach to get WingIDE debugger to stop on exceptions, even within try..except blocks? (A feature I'm used to having in IDEs for other languages.)
> I find myself writing code with exception handling for later robustness, which, during initial debugging, captures programming mistakes that I'd like the IDE to stop at... necessitating rerunning the offending code and single-stepping to find and inspect the problem location. So I'm hoping to avoid that.
> I'm thinking this would need to be enabled on a per-module (or finer-granularity) basis, since, in python, some code uses exceptions as part of expected code paths.
> -- Graham
> Wing IDE users list
The real solution is to use exception handling well - catch specific
exceptions only and only put a try except block around the the line or
group of very few lines that are likely to raise the specific
exception. If there is only one line between try and except then that
is the line that had the problem. If the error reports that you give
are meaningful and as well as printing the exception print the
information that you need to debug then life gets a lot easier.
Personally I would like the opposite of assert to be available - with
assert your conditions are checked only when you are in debug mode, i.e.
not frozen, but not otherwise.
I did manage to come up with the following idea - an assert that you can
conditionally disable - something like the following:
In : class MyError(Exception):
In : DoRaise = False
In : def ConditionalException(*args):
...: if DoRaise:
...: return (args,)
...: return (MyError, )
In : def test():
...: except ConditionalException(ZeroDivisionError) as e:
...: print e
In : test()
ZeroDivisionError Traceback (most recent call last)
<ipython-input-8-ea594c21b25d> in <module>()
----> 1 test()
<ipython-input-7-d7661ce74c2f> in test()
1 def test():
----> 3 1/0
4 except ConditionalException(ZeroDivisionError) as e:
5 print e
ZeroDivisionError: integer division or modulo by zero
In : DoRaise = True
In : test()
integer division or modulo by zero
This might be useful for you and possibly others.
More information about the wingide-users