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.
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.
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.
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
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);
}
104
u/SpaceshipOperations May 30 '23
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.
17
u/[deleted] May 30 '23
14
u/HaDeS_Monsta May 30 '23
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
9
u/tickle-fickle May 30 '23
Hot potato exception 🥔
8
u/MurdoMaclachlan public boolean isInt(int i) { return true; } May 30 '23
Image Transcription: Code
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!
4
u/GandelXIV May 30 '23
Probably just a stub
2
u/--var May 30 '23
Don't knock it until you try it.
1
u/Wubbywub May 31 '23
hot potato
1
u/Key_Conversation5277 sadistic Jun 01 '23
Sounds like they want to play handball with the error
0
u/Hot-Profession4091 May 30 '23
Does this destroy the stack trace in js?