I got a dumb question. In my experience with try/catch, I've only ever used it making API calls. In this instance it's trying to read a file, how does that work in this instance? Can you use try/catch with everything?
The try/catch is one of the ways to catch run-time errors. The code in the try section gets executed until an error is thrown, when an error is thrown, the code goes redirected to the catch section. Try/catch can be used literally anywhere and for everything.
Obviously some other process might have written the file between the two checks. If the second check fails, I’d throw a sleep in there before it so that the other process has more time to write the file out.
16
u/pyker404 Aug 28 '21
That's not bad code. That is pain.
3
u/ogreUnwanted Aug 28 '21
I got a dumb question. In my experience with try/catch, I've only ever used it making API calls. In this instance it's trying to read a file, how does that work in this instance? Can you use try/catch with everything?
31
u/loradan Aug 28 '21
Maybe the dev is preloading dead code so when they have a contest to see who can remove the most # of dead lines they'll win 🤣🤣
14
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 28 '21
Image Transcription: 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!
1
u/[deleted] Sep 05 '21
oooh spwn
3
u/Engineer-Aspire Aug 29 '21 edited Aug 29 '21
How do you use the vscode class in node?
Edit: I found out that it is used for making extensions.
1
u/BarryFruitman Sep 02 '21
Maybe they did that in case somebody deleted the file during the first if block. :-P
1
u/TheHoratian Aug 28 '21
Obviously some other process might have written the file between the two checks. If the second check fails, I’d throw a sleep in there before it so that the other process has more time to write the file out.