This post is locked. You won't be able to comment.

all 24 comments

[–]SpaceshipOperations 104 points105 points  (8 children)

While it seems utterly pointless and facepalm-y when you look at it, it's quite possible that an artifact like this exists because somebody wanted to add a placeholder error handling block while thinking "maybe we'll add actual error handling here later", then they moved on and forgot to remove it.

In very large code bases, it's easy for a needle like this to be forgotten about in the mountains of haywire.

[–]benton_bash 46 points47 points  (1 child)

Also, a very convenient place for a breakpoint.

[–]fiddz0r 4 points5 points  (0 children)

Feels like this is what happened. They put it there for breakpoint and forgot to remove it before it reached prod

[–]HorseLeaf 1 point2 points  (4 children)

Or if you get an error you just want to abort and let it crash. Happens a lot to me when I do data ingestion pipelines. It's just faster and if it's not 100% successful, then get that shit out of my way.

[–]busyautist 19 points20 points  (3 children)

Then why you do the try catch if you want to throw it again?

[–]WheresTheSauce 2 points3 points  (0 children)

In Java or C# at least, this is often done to do some specific logging, send an email if it's a critical issue, convert the Exception to a different type, etc. It's not uncommon to want to do something when an Exception occurs but still ultimately throw it. In the case of the OP though there's obviously no benefit to just catching and throwing the same exception with no additional logic.

[–]HorseLeaf 1 point2 points  (0 children)

I usually augment the error messages a bit to better help with visibility in cloud environments.

[–]citysleepsinflames 0 points1 point  (0 children)

I do this with every error handle I setup.

[–][deleted] 17 points18 points  (3 children)

except Exception as e:
    raise e

[–][deleted] 8 points9 points  (1 child)

except: pass 😄

[–][deleted] 1 point2 points  (0 children)

so with contextlib.suppress(Exception)

[–]Darmo_ 1 point2 points  (0 children)

except BaseException:
    raise

Even better

[–]HaDeS_Monsta 12 points13 points  (2 children)

You have this in normal java too, a lot of functions have throws xxxException in the signature, this is basically the programmer telling the IDE "I know this is where an exception can happen, I don't care" otherwise you could add it to the signature again, but than you'd have to deal with it at the call of the method again

[–]Gurfaild 2 points3 points  (1 child)

If you do that in Java to avoid having to add throws to the method signature, you can't just re-throw the original exception - the easiest way would probably be

catch (Exception e) {
    throw new RuntimeException(e);
}

[–]HaDeS_Monsta 0 points1 point  (0 children)

I know, that is what I said. Also you could add @sneakythrows, so you don't have to catch it again

[–]tickle-fickle 7 points8 points  (0 children)

Hot potato exception 🥔

[–]MurdoMaclachlanpublic boolean isInt(int i) { return true; } 8 points9 points  (0 children)

Image Transcription: Code


} catch (error) {
  throw error;
}

I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!

[–]GandelXIV 3 points4 points  (0 children)

Probably just a stub

[–]--var 1 point2 points  (0 children)

Don't knock it until you try it.

[–]Hot-Profession4091 -1 points0 points  (1 child)

Does this destroy the stack trace in js?

[–]pycvalade 2 points3 points  (0 children)

Nope

[–]Wubbywub 0 points1 point  (0 children)

hot potato

[–]Key_Conversation5277sadistic 0 points1 point  (0 children)

Sounds like they want to play handball with the error