So what is better? To use construction like this:
if (File.Exist(fileName))
{
// do something with file...
}
of just
try
{
// do something with file.
}
catch(Exception ex)
{
}
Does it cost a lot to use method File.Exist()?
Thank you!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Exceptions are not supposed to be used to handle the flow of your application, the idea is to avoid exceptions and not to expect them as normal part of the execution flow.
For 99.999% of the applications, if there is any performance difference, won’t be appreciable. If the file should be there and not finding is a exceptional scenario, you could use the
try catchblock otherwise I’d say you should go for theFile.Existapproach.