Is it better to try/catch exceptions or to use if statements to handle the different outcomes?
I am writing a short program in Java to copy files for convenience, and use the ifs to handle the event where a file does not exist, and declare the throws for each method, but don't use try/catch.
Should I go back and replace those ifs and the related sections with try/catches or is this "acceptable" programming" for sharing with a small community of users?
If by missing, you mean the file should always be there, then that's an exception.
If you mean that a missing file is an ordinary (possible or even likely) occurance, then do not use an exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With