title: Exception Handling in underflow while doing POP in Stack
body: <p>I want to know how to apply <strong>exception handling</strong> when the <strong>top</strong> variable reaches to a value <strong>-1</strong> (no element left to pop). Currently, I am using <strong>cout</strong> to nofity the user about the <strong>stack underflow</strong> and returning <strong>0</strong>, which is not a good practice. What improvement overall can be made to this <strong>pop</strong> function and how to notify user and handle the exception when stack reaches a state of underflow. </p>
  
  <pre><code>int Mystack::pop()
  {
      if (isEmpty())
      {
          std::cout &lt;&lt; "Stack Underflow" &lt;&lt; std::endl;
      }
      else
      { 
          std::cout &lt;&lt; "The popped element is" &lt;&lt; A[top];
          return A[top--];
      }
      return 0;
  }
  </code></pre>
  
  <p>The Main Section :</p>
  
  <pre><code>case 4:
              std::cout &lt;&lt; "POP the element" &lt;&lt; std::endl;
              s1.pop();
              break;
  </code></pre>