I saw long time ago from somewhere saying that handling exception is expensive in terms of stack operations. To avoid the unexpected I guess you should do both, but a check before loading just saves you from unnecessary exception handlings which, if the very first statement is indeed true, would harm the performance.
I saw long time ago from somewhere saying that handling exception is expensive in terms of stack operations. To avoid the unexpected I guess you should do both, but a check before loading just saves you from unnecessary exception handlings which, if the very first statement is indeed true, would harm the performance.
It is an expensive operation as it needs to unwind the stack to get the stack trace.
But if you’re checking a single file you won’t notice it.
If you’re doing it in a tight loop it’ll be very noticeable.
Checking the file exists also has a cost.
I likely wouldn’t bother if I was saving a single file especially as there are other exceptions that could be thrown in the process.