Any way to turn off exception handling? (debugging)

Stephen Hansen apt.shansen at gmail.com
Thu Feb 11 12:45:52 EST 2010


On Thu, Feb 11, 2010 at 9:32 AM, mk <mrkafk at gmail.com> wrote:

> Simon Brunning wrote:
>
>> Not as far as I know. Besides, the chances are that if you were to be
>> able to turn off exception handling altogether your code wouldn't make
>> it as far as the code you are interested in anyway.
>>
>
> Sure, but I could deal with that, jerry-rigging the code as exceptions go
> by, finally reaching the exception I care about.
>
> With all the problems, this would still be much better than nothing. As
> thing are, the only way to do this is guessing and turning particular try /
> except blocks off.
>
> (a really nifty solution would be turning exceptions on or off per module /
> file basis).
>
> IIRC Lua and/or C++ do have this ability, why not Python?
>
> I smell material for a PEP.


Um, Lua has nothing even vaguely like Python's exceptions. It has errors,
and you can "catch" them only by doing a protected call. Otherwise they halt
the entire interpreter.

Python exceptions are pervasive. I don't think you fully understand HOW
pervasive they are-- "turning off" exceptions would utterly break a -vast-
amount of Python code. Exceptions are not errors: exceptions are the
uncommon, the exceptional, case. If one could somehow turn off exceptions,
you can't even do a for loop: every for loop would become infinite--
exceptions are how Python signals the end of an iterator. Think about that,
*every* for loop in Python suddenly breaks.

They're also used in countless other areas which are simply not errors.


>  Is there some way you could monkey patch the exception class to add
>> some logging in there or something?
>>
>
> Sure I can, but how do I get out of Python the info *what called particular
> class/instance*? That is, how do I know who's the caller?
>

Um... run your code in a debugger.

That's what debugger's are -for-.

"pdb" is a simple one. Various IDE's have more advanced ones.

I think you're better served showing us what, "I'm getting an exception (on
socket) handled..." actually means, what is actually happening with real
code and output, and getting pointers on where to look, then trying to
gather material to support an honestly impossible change :)

--S
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100211/f7a97b68/attachment.html>


More information about the Python-list mailing list