title: What should the 'pop()' method return when the stack is empty?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4892108/c-stl-stack-question-why-does-pop-not-throw-an-exception-if-the-stack-is-emp">C++ STL stack question: Why does pop() not throw an exception if the stack is empty?</a>  </p>
  </blockquote>
  
  
  
  <p>When designing a stack in C++, what should the <strong>pop()</strong> method (or <strong>front()</strong> method) return when the stack is empty? Which of the following design is better?</p>
  
  <ol>
  <li>Throw an exception</li>
  <li>Undefined, but require the user calling <strong>isempty()</strong> method to check before calling <strong>pop()</strong></li>
  <li>Return a bool code, while using an extra parameter (a reference) to pass the popped element</li>
  <li>Define an unique <em>empty element</em></li>
  </ol>
  
  <hr>
  
  <p>OK, I see that my question is not that clear, let me try to rewrite it:</p>
  
  <p>There are some data structures which can be implemented based on linked list like stack, queue, and each of them has a methods returning the front element (or the tail). </p>
  
  <p>I want to know, is there any principle guideline about designing such a method regarding the case when the data is empty.</p>
  
  <p>And my definition of better is "easy to use correctly and hard to use incorrectly".</p>