I've actually done this myself. Some IDEs (looking at you, Android Studio) will throw errors (and sometimes even warnings) if you don't catch an error but will happily let you catch-and-rethrow them without warnings. If you're like me and hate seing a single warning when compiling, this is the sort of thing you'll do.
Interestingly, PhpStorm gives you a warning if you try to immediately re-throw an exception and it still counts as an unhandled exception. The image seemingly demonstrates this as there appears to be a warning.
You can satisfy the unhandled exception, at least, with phpDoc:
/**
* @throws Exception
*/
So I'm not quite ready to let them off the hook for this one...
well in some languages like .net, that would actually obscure part of the stacktrace, and if it's sensitive in some nature, that might be logical solution. Aka there is a difference between `throw ex;` and `throw;` and no catch.
The only valid reason I see to do this is to make all exceptions thrown by the code appear as if it originated from here. I don't see why this would be useful though
Some coding conventions expect you catch all exceptions but does not say what to do with them.. Sometimes you could add extra logging in case you are wrapping with your own.
76
u/JLoon92 Nov 10 '21
92
u/aaronjamt Nov 10 '21
I've actually done this myself. Some IDEs (looking at you, Android Studio) will throw errors (and sometimes even warnings) if you don't catch an error but will happily let you catch-and-rethrow them without warnings. If you're like me and hate seing a single warning when compiling, this is the sort of thing you'll do.
6
u/overtrick1978 Nov 10 '21
To set a breakpoint?
23
u/oj_mudbone Nov 10 '21
This is the “hot potato” software pattern
19
u/DJPokis Nov 10 '21
well in some languages like .net, that would actually obscure part of the stacktrace, and if it's sensitive in some nature, that might be logical solution. Aka there is a difference between `throw ex;` and `throw;` and no catch.
10
u/[deleted] Nov 10 '21
They are fans of baseball and going for a double play.
27
u/Cloakknight Nov 10 '21 edited Nov 10 '21
Image Transcription: Code
[Blurred out code]
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
30
u/CaitaXD Nov 10 '21
Haha sex
5
u/muhamadhhassan Nov 10 '21
At least he tried
4
u/coenfused Nov 10 '21
I thought sexception was the funny part
4
u/Nall-ohki Nov 10 '21
Possibly a debug attempt that was left in?
1
u/vatbub Nov 12 '21
It's useless, but much better than the default
or even worse:
3
u/[deleted] Nov 10 '21
The only valid reason I see to do this is to make all exceptions thrown by the code appear as if it originated from here. I don't see why this would be useful though
3
u/Zipdox Nov 10 '21
Task failed successfully
3
u/shizzy0 Nov 10 '21
Dad wouldn’t play catch with me so now I play catch with myself.
2
u/[deleted] Nov 10 '21
$exy
2
u/wageof Nov 10 '21
An attempt was made
1
u/mailslot Nov 10 '21
“Best practices”
1
u/ilep Nov 10 '21
Some coding conventions expect you catch all exceptions but does not say what to do with them.. Sometimes you could add extra logging in case you are wrapping with your own.
1
u/veedant Nov 10 '21
Exception hot-potato
1
u/[deleted] Nov 10 '21
Yet another redundant code.
1
u/[deleted] Nov 10 '21
If you ever thought yourself useless, see this code.
1
u/[deleted] Nov 10 '21
Do thing, If thing don’t do: Do thing
1
u/samj00 Nov 10 '21
Helped with debugging, didn't mean to merge to master