Git history might show a condition to handle a certain type of error differently (or else re-raise like this). And then maybe someone removed that part but left the code like this in the process?
Nope. They’re just catching any exception and just raising it again with more obfuscation since they passed in an exception as an exception parameter (I checked git and surrounding code).
If you do this, you get those awful long and nested stacktraces. Total information overload. Maybe just Exception(str(e)) to know something happened but if you want more details, good luck and maybe some debugging? ;-)
You'd definitely use a NotImplemented Eception for that. For why its done I assume it's to raise the exception at a diff point? No idea why its done tbh
If you package you application with py2exe the execution directory lives in sys.Meipass so you can check it. If you get an attributeerror exception it mean you are running it as a script and you can just pass
If you are working on a proprietary product, never post recognizable chunks of code online.
There is a clear pattern here - adding methods like failsafe_info_dialog and failsafe_error_dialog would be better. But if it was a one-time trick accompanied by a reasonable comment, it would be fine with me.
The code is your company's intellectual property. Posting it online is literally a crime (although a petty one). You may get in trouble easily for no good reason.
Yeah, absolutely, that's why I said "fine", not "great" XD
Of the top of my head, the situations and solutions are:
You're at the top scope of the program and just want to make sure it doesn't crash: Don't do that. Just crash, setup automatic restart and monitoring. If absolutely necessary, then do the "fine" thing and at least log. But like, really, avoid it, because your state is now fucked and you are trying to keep chugging along instead of restarting from scratch, and that's only gonna cause more trouble.
You're doing something that might fail, but you don't care at this particular point, because the rest of the code will retry and eventually surface the error in other ways (notification to user, telemetry, 500 http error, etc.): Either use an alternative approach that returns none (dict.get instead of [], for instance), catch the proper, specific exception (e.g., KeyError), or let it bubble up and be handled by the framework (web frameworks will usually convert exceptions into 500 errors, instead of killing the app server)
I can't think of a third case, haven't got breakfast yet.
Unfortunately I can't judge considering the atrocities I've committed... I'm looking at you try { everything inside main() } followed by executing the program again. I'd feel guilty if it didn't work so well for the long game.
93
u/jellotalks Apr 17 '26
You think that's bad, I found a
in prod
65
u/IanisVasilev Apr 17 '26
There are good reasons for this sometimes. Without more context, it is difficult to judge.
9
u/fakehalo Apr 17 '26
Unfortunately I can't judge considering the atrocities I've committed... I'm looking at you try { everything inside main() } followed by executing the program again. I'd feel guilty if it didn't work so well for the long game.
2
u/Risc12 Apr 18 '26
This could be fine if it is a completely optional thing that has many reasons to go wrong and you don’t actually care if they do go wrong.
Not sure what examples of such a situation would be, but without any more context this is hard to judge.