title: Using Throwable for Things Other than Exceptions
body: <p>I have always seen Throwable/Exception in the context of errors. But I can think of situations where it would be really nice to extend a <code>Throwable</code> just to break out of a stack of recursive method calls. Say, for example, you were trying to find and return some object in a tree by the way of a recursive search. Once you find it stick it in some <code>Carrier extends Throwable</code> and throw it, and catch it in the method that calls the recursive method. </p>
  
  <p>Positive: You don't have to worry about the return logic of the recursive calls; since you found what you needed, why worry how you would carry that reference back up the method stack.</p>
  
  <p>Negative: You have a stack trace that you don't need. Also the <code>try/catch</code> block becomes counter-intuitive.</p>
  
  <p>Here is an idiotically simple usage:</p>
  
  <pre><code>public class ThrowableDriver {
      public static void main(String[] args) {
          ThrowableTester tt = new ThrowableTester();
          try {
              tt.rec();
          } catch (TestThrowable e) {
              System.out.print("All good\n");
          }
      }
  }
  
  public class TestThrowable extends Throwable {
  
  }
  
  public class ThrowableTester {
      int i=0;
  
      void rec() throws TestThrowable {
          if(i == 10) throw new TestThrowable();
          i++;
          rec();
      }
  }
  </code></pre>
  
  <p>The question is, is there a better way to attain the same thing? Also, is there something inherently bad about doing things this way?</p>