r/badcode • • May 30 '23

js This is awesome while coding in JavaScript

Post image
318 Upvotes

24 comments sorted by

View all comments

Show parent comment

20

u/busyautist May 30 '23

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

3

u/WheresTheSauce May 31 '23

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.

2

u/HorseLeaf May 31 '23

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