title: getting wrong line number when raising java exception
body: <p>I am trying to create code where if an Application Error is found, an Exception is thrown. The idea was that I could also get the line number where the error took place.</p>
  
  <p>What I have now is as follows:</p>
  
  <pre><code>try {
      // ...
      if ( customerid &lt;= 0 ) throw new ApplicationError( " =&gt;invalid customerid  passed in" );
      // ...
  }
  catch ( ApplicationError e )
  {
  
              throw new RuntimeError(" =&gt; CLASS :  "
                      + this.getClass().getSimpleName() + " =&gt; LINE : "
                      + Thread.currentThread().getStackTrace()[1]
                      + " =&gt; MESSAGE : " + e.getMessage()
                      + " =&gt; CAUSED BY : " + e.getCause());
  }
  </code></pre>
  
  <p>Just as a note, I have created an exception called RuntimeError whose only purpose is to print any error messages found.</p>
  
  <p>But ...
  The problem is that in the code,
  The part: <code>Thread.currentThread().getStackTrace()[1]</code> returns the line number that thee code <code>Thread.currentThread().getStackTrace()[1]</code> is on. </p>
  
  <p>Not the line number that throw new <code>ApplicationError( " =&gt;invalid customer passed in );</code> is on</p>
  
  <p>I have tried using:</p>
  
  <pre><code>Thread.currentThread().getStackTrace()[0] and
  Thread.currentThread().getStackTrace()[2]
  </code></pre>
  
  <p>but none of these have worked. Java 1.7 is being used now - but the idea is to go to 1.8 a quite a bit later. </p>
  
  <p>How can this be fixed?</p>
  
  <p><strong>Update</strong></p>
  
  <p>Removed as per the request of @Jean-Baptiste Yunès  I have resolved the second issue on my own.</p>