Python Forum
an easy way to disable exception handling
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
an easy way to disable exception handling
#1
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
See here:
https://dev.to/wemake-services/python-ex...ttern-17o9
Reply
#3
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
instead, i went with TabError which doesn't happen for me, anymore.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#5
(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?
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#6
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#7
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Star python exception handling handling .... with traceback mg24 3 1,216 Nov-09-2022, 07:29 PM
Last Post: Gribouillis
  Errors when trying to disable tkinter checkbutton rrick_88 7 2,752 Feb-17-2022, 10:30 PM
Last Post: deanhystad
  TicTacToe Game Add Exception Handling and Warning Function ShaikhShaikh 5 2,376 Nov-03-2021, 05:02 PM
Last Post: deanhystad
  Exception handling in regex using python ShruthiLS 1 2,330 May-04-2020, 08:12 AM
Last Post: anbu23
  Exception handling Calli 2 2,409 Apr-20-2020, 06:13 PM
Last Post: Calli
  Handling exception from a module dchi2 11 5,499 Nov-25-2019, 08:47 AM
Last Post: dchi2
  problem using custom exception handling in python srm 3 3,000 Jul-03-2019, 09:10 PM
Last Post: ichabod801
  exception handling KyawMyo 3 2,782 May-07-2019, 07:53 AM
Last Post: buran
  Database operation exception handling LostInCode 1 2,449 Jan-03-2019, 07:50 PM
Last Post: jeanMichelBain
  During handling of the above exception, another exception occurred Skaperen 7 26,728 Dec-21-2018, 10:58 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020