title: Override fillInStackTrace for control flow / performance
body: <p>Note: although seemingly similar, this is not a duplicate of <a href="https://stackoverflow.com/questions/1520859/overriding-fillinstacktrace-for-a-standard-jvm-exceptions">Overriding fillInStackTrace for a standard JVM Exceptions</a></p>
  
  <p>What are your thoughts on overriding fillInStackTrace on checked exceptions to return null?</p>
  
  <p>The advantages are:</p>
  
  <ol>
  <li>you can use said exception for control flow without the performance penalty of filling in a stack trace.</li>
  <li>You can pass an arbitrary object back to the caller as a property of the exception, regardless of the signature of the method that throws said exception. (e.g. an error message, a partly-initialed value, etc.)</li>
  </ol>
  
  <p>The biggest disadvantage is simply that this is not standard practice.</p>
  
  <p>But the only way of doing something similar is:</p>
  
  <ol>
  <li>returning null, or a "special value" back (e.g. -1) to signify something went wrong.</li>
  <li>changing the callee to return a composite object of the value &amp; error code, and having the caller inspect this object to see what happened.</li>
  </ol>
  
  <p>I'm looking for an arguments that are extremely convincing for or against the practice of overriding fillInStackTrace, or an argument that shows it's no big deal either way.</p>
  
  <p>Apparently RIFE uses this technique:</p>
  
  <p><a href="http://www.rifers.org/" rel="nofollow noreferrer">http://www.rifers.org/</a> <br>
  <a href="http://cretesoft.com/archive/newsletter.do?issue=129" rel="nofollow noreferrer">http://cretesoft.com/archive/newsletter.do?issue=129</a></p>
  
  <p>Below is a standard way of doing something, and a contrived example using this technique.</p>
  
  <pre><code>    //standard
      int i = "foo".indexOf('f');
      if (i&lt;0){
        System.out.println("found f");
      } else {
        System.out.println("no f here");
      }
      //example
      try {
        "foo".indexOf('f');
        System.out.println("found f");
      } catch (NotFound e) {
        System.out.println("no f here");
      }
  </code></pre>