In: Computer Science
FileSystem.delete(...) method returns a boolean when you attempt to delete a file that does not exist in the file system. Apparently, Hadoop framework developers decided to return boolean rather than throwing an Exception. If you were the lead developer, would you have taken the same approach? Why? Why Not?
This is a great question.If I were to be a lead developer in this case , would have gone with the same approach.
There are 2 major reason choosing this approach:
1.Control flow with throwing exception is far more complicated than returning a variable(boolean in this case) and even more so if the Exception is a checked one . By choosing exceptions control flow we are unnecessarily complicating the code which could have been written in a neater manner.And cleaner the code better it is to maintain.
2.Returning a variable allows the client/user who is consuming the apis that we have developed far more flexibility and ease in development.He can use if, while, switch case etc. to handle various situation instead of catching different kinds of exception.
Hence , we can conclude that using the approach without exception is far superior to one which throws Exception and should be used unless absolutely required.