Is there any reason why it’s better to use a try/catch statement when one can check to see if a value that is designated to indicate a problem is returned?
For example a function prime factors a number. If a negative integer is passed to it would it be “better” for an exception to be thrown or a particular value returned (that would never be a legitimate value, say -1).
If a function doesn’t need to return something would it be less efficient to return true on success and false on failure, as opposed to throwing something?
The use of a Try/Catch versus returning a boolean value has been discussed for a while. I found this StackOverflow article that might add some insight. For myself I tend to use both the Try/Catch and the boolean return. It depends when a method is being called. As well, sometimes it is best to let an error bubble up the stack so it can be caught and dealth with effieciently.
Finally, if your find you are not getting any answers here you can also try https://softwareengineering.stackexchange.com/