Binette@lemmy.ml to Learn Programming@programming.devEnglish · 2 months agoIs it better to check if a file exists before trying to load it, or to try to load it, and catch the error and move on?message-squaremessage-square15fedilinkarrow-up123arrow-down10file-text
arrow-up123arrow-down1message-squareIs it better to check if a file exists before trying to load it, or to try to load it, and catch the error and move on?Binette@lemmy.ml to Learn Programming@programming.devEnglish · 2 months agomessage-square15fedilinkfile-text
minus-squareRonSijm@programming.devlinkfedilinkarrow-up9·2 months agoWell you need to try and catch when getting the file anyways, it’s probably very rare but imagine a scenario of: Check if file exists user deletes file in between (try) opening the file Or the file could exist, but you don’t have permissions to actually open it. So a bunch of languages / already have their own “try open file”
Well you need to try and catch when getting the file anyways, it’s probably very rare but imagine a scenario of:
Or the file could exist, but you don’t have permissions to actually open it.
So a bunch of languages / already have their own “try open file”