title: C++ Exception Handling between Classes
body: <p>I'm working on exception handling and right now I'm stuck on a problem I'm working on out of my book. What I'm trying to do is add an try-catch block inside my main function to catch an exception that is thrown by a function that I am using. Here are snippets of where I am having trouble on.</p>
  
  <p><code>EmptyStackPopException</code> is an empty Exception class that I put into my <code>stack.h</code> file that can be seen here:</p>
  
  <pre><code>class EmptyStackPopException {
      };
  </code></pre>
  
  <p>Here is the function that is supposed to throw this Exception.</p>
  
  <pre><code>T Stack&lt;T&gt;::pop( ) throw (EmptyStackPopException)
      {
          if (isEmpty( ))
          {
          throw EmptyStackPopException();
          }
  
          T result = top-&gt;getData( );
  
          Node&lt;T&gt; *discard;
          discard = top;
          top = top-&gt;getLink( );
  
          delete discard;
  
          return result;
      }
  </code></pre>
  
  <p>Here is a snippet of my main function where the exception is supposed to be caught:</p>
  
  <pre><code>try {
      cout &lt;&lt; s.pop( );
  } catch (EmptyStackPopException) {
      cout &lt;&lt; "EmptyStackPopException: You didn't enter anything in." &lt;&lt; endl;
          }
  </code></pre>
  
  <p>Now the issue that I'm having is I cannot compile because of these following errors:</p>
  
  <pre><code>..\assignment8\main.cpp(29) : error C2061: syntax error : identifier 'EmptyStackPopException'
  ..\assignment8\main.cpp(29) : error C2310: catch handlers must specify one type
  ..\assignment8\main.cpp(32) : error C2317: 'try' block starting on line '27' has no catch handlers
  </code></pre>
  
  <p>I'm pretty sure that the only error I have at the moment is in the main function, EmptyStackPopException is not able to be detected in the client program which causes the last two errors. </p>