title: Using throw to replace return in C++ non-void functions
body: <p>In C++ functions, is it a good practice to replace <code>return</code> with <code>throw</code>? For example, I have the following code</p>
  
  <pre><code>// return indices of two numbers whose sum is equal to target
  vector&lt;int&gt; twoSum(vector&lt;int&gt;&amp; nums, int target) {
      for(int i=0; i&lt;nums.size()-1; ++i)
          for(int j=i+1; j&lt;nums.size(); ++j)
          {
              if(nums[i] + nums[j] == target) return vector&lt;int&gt;{i, j};
          }
      // return vector&lt;int&gt;{};
      throw "no solution";
  }
  </code></pre>
  
  <p>The code above compiles with my GCC 7.2.</p>