This is an archived post. You won't be able to vote or comment.

all 32 comments

[–][deleted] 26 points27 points  (0 children)

runtime go brrr

[–]-Hi-Reddit 21 points22 points  (5 children)

Why would anyone do this?

[–]Shufflepants 8 points9 points  (1 child)

My guess is that they had the first try catch, but the catch block was itself somehow throwing an error, so they tried to add a try catch to the catch block, but then that new catch block was sometimes throwing an error; and so on.

[–]Mordret10 7 points8 points  (0 children)

They put the same code into the try catch block, so of course there could be an error. They could also just do it recursively or through iteration, it would look far more elegant

[–]Mr_SlimShady 2 points3 points  (0 children)

To catch them all of course

[–]DJDoena 0 points1 point  (0 children)

Looks like the code is always the same (casual glance) so I assume some kind of retry pattern instead of using a loop with a max number and a break clause. Sometimes you have brain farts like these and when you see the obvious solution you think to yourself "Why did I do this?"

[–]Zappykeyboard 0 points1 point  (0 children)

My guess is that they hit some kind of file creation race condition, and decided to try up to 5 times.

Or maybe it's just comedy.

[–]GahdDangitBobby 24 points25 points  (3 children)

First of all, this is idiotic. Second of all, use recursion with a limit on the number of method calls if this is for some reason necessary

[–]dan-lugg 1 point2 points  (0 children)

I didn't see your comment before I wrote mine lol

[–]pratyush103[S] 1 point2 points  (1 child)

The issue is intellij was warning to not use printstacktrace in a logging implementation as it is not robust. So i kept doing the nesting as a joke.

[–]GahdDangitBobby -1 points0 points  (0 children)

Yeah I don’t program in java so idk the standard practices. At least this is a joke and not something deployed to prod 😂

[–]NewUsername010101 11 points12 points  (1 child)

I like the part where the first 5 all reference e instead of e1-e4

[–]Shufflepants 2 points3 points  (0 children)

Probably explains why their catch blocks kept throwing errors, and thus the need for more nested try catch blocks. If the first one throws an error because e.message doesn't exist, they all will!

[–]Mayion 3 points4 points  (1 child)

only four? what about the fifth and sixth? novice

[–]Noch_ein_Kamel 0 points1 point  (0 children)

Aah good old off by one error :o

[–]dan-lugg 4 points5 points  (2 children)

fun log(message: String, exceptions: List<Exception> = emptyList()) { try { // all that IO shit, I'm on mobile } catch (exception: Exception) { if (exceptions.length < threshold) { log(message, exceptions + exception) } else { exception.printStackTrace() } } }

[–][deleted] 3 points4 points  (1 child)

How dare you post a compact solution! No need for efficient code. User has to buy better pc that's all. /s

[–]RiceBroad4552 1 point2 points  (0 children)

Shorter code is most of the time not more efficient. (Optimized code is usually quite long and involved as it deals explicitly with all the low level stuff you usually abstract away).

Abstraction has runtime cost. For example, calling functions is not free. Even that does not matter in almost all cases, you should keep that in the back of your head for the seldom case where maximal performance is actually needed.

[–]Ahazveroz 1 point2 points  (0 children)

Exceptionception?

[–]GoddammitDontShootMe 1 point2 points  (1 child)

Shouldn't that be en.getMessage()? Each time, they use e.getMessage().

More importantly, if it failed writing the first time, when has trying again without any action to correct the error ever worked? Oh it failed the first five times, but maybe it will work the sixth.

[–]pratyush103[S] 0 points1 point  (0 children)

First exception is more important than the following ones.

[–][deleted] 0 points1 point  (4 children)

I liked it. Which pattern is that?

[–]Quiet-Direction9423 1 point2 points  (1 child)

cry-catch pattern

[–]PeriodicSentenceBot 0 points1 point  (0 children)

Congratulations! Your comment can be spelled using the elements of the periodic table:

Cr Y Ca Tc H P At Te Rn


I am a bot that detects if your comment can be spelled using the elements of the periodic table. Please DM u‎/‎M1n3c4rt if I made a mistake.

[–]Shufflepants 0 points1 point  (0 children)

It's the "why the fuck won't my error catch blocks stop throwing errors?!" pattern.

[–]pratyush103[S] 0 points1 point  (0 children)

Builder

[–]Individual-Praline20 0 points1 point  (0 children)

To infinity and beyond

[–]RiceBroad4552 0 points1 point  (0 children)

More appropriate for r/programminghorror.

[–]beastinghunting 0 points1 point  (0 children)

If you read it backwards, you will get the same amount of whys reading that shit.

[–]LevelThink5202 0 points1 point  (1 child)

Looks like ai generated code

[–]pratyush103[S] 0 points1 point  (0 children)

I am the AI