title: Throwing exception vs return code
body: <p>I'm implementing my own queue which blocks on <code>.pop()</code>. This function also accepts additional argument which is a timeout. So at the moment I have such code:</p>
  
  <pre><code>template &lt;class T&gt;
  class BlockingQueue {
  
  private:
      std::queue&lt;T&gt; m_queue;
      std::mutex m_mutex;
      std::condition_variable m_condition;
  
  public:
      T pop(uint64_t t_millis) {
          std::unique_lock&lt;std::mutex&gt; lock(m_mutex);
          auto status = m_condition.wait_for(
              lock,
              std::chrono::milliseconds(t_millis),
              [=] {
                  return !m_queue.empty();
              }
          );
          if (!status) {
              throw exceptions::Timeout();
          }
          T next(std::move(m_queue.front()));
          m_queue.pop();
          return next;
      };
  }
  </code></pre>
  
  <p>where <code>exceptions::Timeout</code> is my custom exception. Now I've been thinking  about this exception throwing from the performance point of view. Would it be better to return some kind of return code from that function? How does that affect performance?</p>
  
  <p>Also since <code>.pop</code> already returns something how would you implement additional return code? I suppose some new structure that holds both <code>T</code> and a return code would be needed. Is that increase in complexity really worth it?</p>