How to handle failed methods: by using exceptions or making the methods return bool?

Viewed 237

How to handle failed methods:

  1. using exceptions
  2. making the methods return bool

The first approach is when something goes wrong to throw an exception. But the problematic code needs to be placed in a try block, and then you need to write the catch block.

The second approach you need to check the return value from the method, and then do something.

So basically isn't it the same mechanism? You have two parts: detecting that something goes wrong and then doing something about it. So does it matter then which approach I use?

7 Answers
Related