title: Which is the better design approach - to return bool or to throw an exception?
body: <p>I'm wondering which approach is better. Let's say we have a method that, for example, sends a notification email.</p>
  
  <pre><code>void SendNotificaitonEmail();
  </code></pre>
  
  <p>So, I can edit my <code>SendNotificaitonEmail()</code> method so it now does the following:</p>
  
  <pre><code>bool SendNotificationEmail(out string errorMessage)
  {
      try
      {
          // This is the code that handles the actual sending of the email.
          // ..
      }
      catch(Exception ex)
      {
          errorMessage = ex.Message;
          return false;
      }
  }
  </code></pre>
  
  <p>But isn't this wrong, in terms of design? For example, the <code>errorMessage</code> variable has nothing to do with the concept of <code>SendNotificationEmail()</code> method. Moreover, I should then add two new variables to all of my methods - a boolean one, stating the result of the method (true/false), and a string one, containing the error message, if one occurs. </p>
  
  <p>The other way is to create my custom exceptions and handle them in the other methods that are invoking the first one.</p>
  
  <pre><code>public void SendNotificaitonEmail()
  {
      try
      {
          // This is the code that handles the actual sending of the email.
          // ..
  
          if (somethingIsWrong == true)
          {
              throw new MyCustomException();
          }
      }
      catch(Exception ex)
      {
          // Other exception handling code.
          // ..
      }
  }
  
  public void OtherMethod()
  {
      try
      {
          SendNotificaitonEmail();
      }
      catch(MyCustomException ex)
      {
          // Exception handling code.
          // ..
      }
  }
  </code></pre>
  
  <p><strong>Edit</strong>
  Let's say I want to be sure that all of the operations, handled in the DAL code execute successfully.</p>
  
  <p>I have methods like <code>UpdateUserData</code>, <code>GetUserById</code>, <code>ChangeUserPicture</code>.</p>
  
  <p>So, if I want to check whether these operations have executed successfully, I should add some additional variables like:</p>
  
  <pre><code>bool UpdateUserData(User userToUpdate, out string errorMessage); 
  User GetUserById(int id, out bool isError, out string errorMessage);
  bool ChangeUserPicture(Picture picture, int id, out string errorMessage);
  // ..
  </code></pre>
  
  <p>I have a simple app that uses all these methods:</p>
  
  <pre><code>string errorMessage;
  bool isUserUpdatedSuccessfully = UpdateUserData(someUserToUpdate, out errorMessage); 
  
  if (isUserUpdatedSuccessfully == true)
  {
      // If the DAL operation was executed successfully, do something..
  }
  else
  {
      // Code that informs the user that an error has occurred.
      MyCustomErrorLogger(errorMessage);        
  }
  </code></pre>