Python Forum
an easy way to disable exception handling - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: an easy way to disable exception handling (/thread-18796.html)



an easy way to disable exception handling - Skaperen - Jun-01-2019

while debugging code, often my exception handling obscures what is really going on. i usually have to take the exception handling out. and that is typically a lot of work, especially saving that code or typing it all back in. and, of course, i have to unindent the active code. so what i have done is replace the try: with if 1: and the except: with if 0:. but even that is a fair amount of typing to put it in and undo it. my latest thought is to just change the exception being handled to one that mostly never happens (when my code is trying to run). would SyntaxError be a viable choice (in running code being debugged). the idea is to temporarily be handling an exception that does not happen so that the exception that really does happen is not handled, letting it stop the code and dump the stack.


RE: an easy way to disable exception handling - heiner55 - Jun-01-2019

See here:
https://dev.to/wemake-services/python-exceptions-considered-an-anti-pattern-17o9


RE: an easy way to disable exception handling - Skaperen - Jun-01-2019

too much code being added to support coding. things should ideally be expressed as simple as possible and added on mechanisms should be added after the coding is done,like in the compiling phase.


RE: an easy way to disable exception handling - Skaperen - Jun-01-2019

instead, i went with TabError which doesn't happen for me, anymore.


RE: an easy way to disable exception handling - perfringo - Jun-02-2019

(Jun-01-2019, 04:10 AM)Skaperen Wrote: often my exception handling obscures what is really going on.

Idea of exception handling is to handle expected exceptions and propagate non-expected as usual. Can you give some examples/hints how exception handling obscures what is really going on?


RE: an easy way to disable exception handling - Skaperen - Jun-02-2019

i'm handle lots of excepts in this case because there are many possible during these function calls.. but while debugging i would rather not handle any and let things dump and come to a screeching halt. but taking out the code is more of a hassle (indent changes) than changing it to handle something i really know won't happen.


RE: an easy way to disable exception handling - Gribouillis - Jun-02-2019

Quote:often my exception handling obscures what is really going on.

Far from being an anti-pattern, exceptions are the best friends of the python programmer. They carry all the key information that makes debugging a breeze.

As often as you can, don't handle exceptions. Let them propagate unless it really makes a lot of sense to handle them.