title: Catch Multiple Custom Exceptions? - C++
body: <p>I'm a student in my first C++ programming class, and I'm working on a project where we have to create multiple custom exception classes, and then in one of our event handlers, use a <code>try/catch</code> block to handle them appropriately.</p>
  
  <p>My question is: How do I catch my <strong>multiple</strong> custom exceptions in my <code>try/catch</code> block? <code>GetMessage()</code> is a custom method in my exception classes that returns the exception explanation as a <code>std::string</code>. Below I've included all the relevant code from my project.</p>
  
  <p><strong><em>Thanks for your help!</em></strong></p>
  
  <p><strong>try/catch block</strong></p>
  
  <hr>
  
  <pre><code>    // This is in one of my event handlers, newEnd is a wxTextCtrl
  try {
      first.ValidateData();
      newEndT = first.ComputeEndTime();
      *newEnd &lt;&lt; newEndT;
  }
  catch (// don't know what do to here) {
      wxMessageBox(_(e.GetMessage()), 
                   _("Something Went Wrong!"),
                   wxOK | wxICON_INFORMATION, this);;
  }
  </code></pre>
  
  <p><strong>ValidateData() Method</strong></p>
  
  <hr>
  
  <pre><code>void Time::ValidateData()
  {
      int startHours, startMins, endHours, endMins;
  
      startHours = startTime / MINUTES_TO_HOURS;
      startMins = startTime % MINUTES_TO_HOURS;
      endHours = endTime / MINUTES_TO_HOURS;
      endMins = endTime % MINUTES_TO_HOURS;
  
      if (!(startHours &lt;= HOURS_MAX &amp;&amp; startHours &gt;= HOURS_MIN))
          throw new HourOutOfRangeException("Beginning Time Hour Out of Range!");
      if (!(endHours &lt;= HOURS_MAX &amp;&amp; endHours &gt;= HOURS_MIN))
          throw new HourOutOfRangeException("Ending Time Hour Out of Range!");
      if (!(startMins &lt;= MINUTE_MAX &amp;&amp; startMins &gt;= MINUTE_MIN))
          throw new MinuteOutOfRangeException("Starting Time Minute Out of    Range!");
      if (!(endMins &lt;= MINUTE_MAX &amp;&amp; endMins &gt;= MINUTE_MIN))
          throw new MinuteOutOfRangeException("Ending Time Minute Out of Range!");
      if(!(timeDifference &lt;= P_MAX &amp;&amp; timeDifference &gt;= P_MIN))
          throw new PercentageOutOfRangeException("Percentage Change Out of Range!");
      if (!(startTime &lt; endTime))
          throw new StartEndException("Start Time Cannot Be Less Than End Time!");
  }
  </code></pre>
  
  <p><strong>Just one of my custom exception classes, the others have the same structure as this one</strong></p>
  
  <hr>
  
  <pre><code>class HourOutOfRangeException
  {
  public:
          // param constructor
          // initializes message to passed paramater
          // preconditions - param will be a string
          // postconditions - message will be initialized
          // params a string
          // no return type
          HourOutOfRangeException(string pMessage) : message(pMessage) {}
          // GetMessage is getter for var message
          // params none
          // preconditions - none
          // postconditions - none
          // returns string
          string GetMessage() { return message; }
          // destructor
          ~HourOutOfRangeException() {}
  private:
          string message;
  };
  </code></pre>