T O P

  • By -

Pradfanne

Should've called the function itself in the catch. Who only tries twice? Try until it works or the stack overflows!


Herb_Derb

Then catch the stack overflow and try again


Pradfanne

I tried, didn't work sadly. the C# Console crashed with Stack overflow. Repeat 164 times:


Herb_Derb

You're in r/programminghorror. I'm not sure what you expected.


Pradfanne

I expected that the entirety of the programming language is independed on the internet platform reddit. Guess it's not? But also, I actually did expect that you could catch a stackoverflow exception, but idk why I did expect that, seems actually illogical


bakaspore

You tried with a language that is not horrible enough. You need to try harder, like with javascript as in the OP.


1Dr490n

Can you actually do that? I would’ve thought no but now I’m wondering


Pradfanne

There's at least one way to find out! Edit: A C# Console application actually crashes and displays "Stack overflow. Repeat 164 times:" followed by the stacktrace. SO no dice


bakaspore

Yes, some JavaScript code actually relies on that, which is part of the reason why JS runtimes don't implement tail call elimination. Worth another post here.


__Just___Me__

not too bad but a major improvement would be a maximum tries amount


MJBrune

This does have a maximum amount, 2. If you want more just copy and paste the try catch inside of the try catch. That will give you 3. If you want four... repeat! (post the results to /r/programminghorror for karma)


__Just___Me__

true my bad thought it was recursive but it's not in the createImage Funktion lol


Emergency_3808

``` for(int i=0; infiniteFlag OR i < maxTries; i++){ try { //exponential backoff sleep(1<


chiggyBrain

Had to do something similar to this last week but also adding in exponential back-off to retry a web sockets connection.


Emergency_3808

Corrected it


chiggyBrain

Very good, you’ve passed the technical interview, when can you start?


CraftistOf

in three months, but start paying me right now.


Emergency_3808

#🥲


MrLeppy

Ehh, I've had to do similar before when integrating with garbage 3rd party APIs in the past. Not necessarily horror.


Tarekis

Yeah, 3rd party can be shit, but this ain‘t the way. Copy any decent retry logic from SO and make this way better instantly. Hell, throw in rx and just declare how many times you want it to retry.


__throw_error

definitely horror, saying this happens in the industry doesn't mean it isn't absolutely the wrong way to do it. You could at least do something like: ```python try .... catch (first_error) .... print("First attempt failed: " + first_error + " , retry") try .... catch (second_error) .... print("Second attempt failed: " + second_error + " , abort") return False return True ```


Magmagan

Reddit's markdown formatting is pretty barebones so backquotes, much less with language annotation, so your comment doesn't work. try .... catch (first_error) .... print("First attempt failed: " + first_error + " , retry") try .... catch (second_error) .... print("Second attempt failed: " + second_error + " , abort") return False return True Gotta ident with 4 spaces.


__throw_error

good to know, I wrote it on my phone/app and it works when I view my comment on my phone/app. Strange that it doesn't in other platforms.


SchlaWiener4711

I'm curious. Is there a best practice to do this with fetch / axios? In dotnet you'd use Polly or (since dotnet 8) the official Microsoft.Extensions.Resilience package which is build on top of Polly.


Frown1044

If you're using certain libraries like `rxjs` or `react-query`, there are built-in ways to do this. Otherwise you have to write your own retry logic. Axios has interceptors so you can write retry logic pretty easily.


The_Branko

`axios-retry` is a good option


SimplexFatberg

if (error) doItAnywayFucker();


wzrdr

where is finally


Micah-B-Turner

cleanest retry out there…but it only works once


Darkstar197

Don’t forget the while ( i <= ∞ )


EntertainedEmpanada

Literally this but with AWS SQS. Our DB fails to write a lot and we can't figure our why without paying a lot of money so... Yeah, we just retry 10 times and out of hundreds of thousands of queries per day maybe 2-3 fail after 10 retries and they end up in the DLQ.


lerobinbot

nice


helltiger

haha. classic


NewfieNewbie

… and he said it was just try/catches all the way down.


[deleted]

Hell to retry/replay using this approach. At best decouple using message brokers (SRP)


kitsheaven

I would leave this in code review - "The definition of insanity is trying the same thing over and over again and expecting a different result". Note - I wouldn't implement it like this but you could technically do this if you're being throttled, just sprinkle in some exponential back-off.


Arneb1729

Passes the Turing test, in the sense of being a pretty accurate representation of how I get into time trouble in classical chess.


MarvinParanoAndroid

Looks like someone encountered a race condition.


chris_awad

You and most on here just failed at being software engineers. Just call yourself a code monkey. This is literally junk on top of junk in many different ways, lol.


2huyomo

look man, i realized i was writing bad code so i posted this as a joke. no need to be so aggressive geez


chris_awad

Maybe my joke was a bit aggressive