title: Handling exceptions for multiple calls to functions of a class
body: <p><strong>I can't get my head around WHEN to throw and catch exceptions for when I call functions from classes.</strong></p>
  
  <p>Please imagine that my <code>QuizMaker</code> class looks like this:</p>
  
  <pre><code>// Define exceptions for use in class
  private class CreateQuizException extends Exception {}
  private class InsertQuizException extends Exception {}
  
  class QuizMaker()
  {
  
      // Define the items in my quiz object
      $quiz_id = null;
      $quiz_name = null;
  
      // Function to create a quiz record in the database
      function CreateQuizInDatabase()
      {
  
          try
          {
  
              $create_quiz = // Code to insert quiz
  
              if (!$create_quiz)
              {
                  // There was an error creating record in the database
                  throw new CreateQuizException("Failed inserting record");
              }
              else
              {
                  // Return true, the quiz was created successfully
                  return true;
              }
  
          }
          catch (CreateQuizException $create_quiz_exception)
          {
              // There was an error creating the quiz in the database
              return false;
          }
      }
  
      function InsertQuestions()
      {
          try
          {
              $insert_quiz = // Code to insert quiz
  
              if (!$insert_quiz)
              {
                  // There was an error creating record in the database
                  throw new CreateQuizException("Failed inserting quiz in to database");
              }
              else
              {
                  // Success inserting quiz, return true
                  return true;
              }
          }
          catch (InsertQuizException $insert_exception)
          {
              // Error inserting question
              return false;
          }
      }
  }
  </code></pre>
  
  <p><strong>... and using this code, I use the class to create a new quiz in the database</strong></p>
  
  <pre><code>    class QuizMakerException extends Exception {}
  
  try
  {
      // Create a blank new quiz maker object
      $quiz_object = new QuizMaker();
  
      // Set the quiz non-question variables
      $quiz_object-&gt;quiz_name = $_POST['quiz_name'];
      $quiz_object-&gt;quiz_intro = $_POST['quiz_intro'];
              //... and so on ...
  
      // Create the quiz record in the database if it is not already set
      $quiz_object-&gt;CreateQuizRecord();
  
      // Insert the quiz in to the database
      $quiz_object-&gt;InsertQuestions();
  
  }
  catch (QuizMakerException $quiz_maker_error)
  {
      // I want to handle any errors from these functions here
  }
  </code></pre>
  
  <p>For this piece of code, I want to call a <code>QuizMakerException</code> if any of the functions don't perform what I want them to (at the moment they return TRUE or FALSE).</p>
  
  <p>What is the <em>correct</em> way to go about catching when any of the functions in this code does not perform what I want them to?  At the moment they simply return TRUE or FALSE.</p>
  
  <ul>
  <li>Do I <em>really</em> have to put lots of if/else statements between calling each function, I thought that was the whole point in exceptions, they simply halt the execution of further statements within the try/catch?</li>
  <li>Do I throw a QuizMakerException from within the <code>catch</code> of my functions?</li>
  </ul>
  
  <p>What is the right thing to do?</p>
  
  <p>Help!</p>