Java: Determining Current Call Stack (For Diagnostic Purposes)
<p>For diagnostic purposes I sometimes need to store the call stack that lead to a given state transition (such as granting a lock, committing a transaction, etc.) so that when something goes wrong later I can find out who originally triggered the state transition.</p>

<p>Currently, the only way I am aware of to retrieve the call stack looks like the following code snippet, which I consider terribly ugly:</p>

<pre><code>StackTraceElement[] cause;
try {
  throw new Exception();
} catch (Exception e) {
  cause = e.getStackTrace();
}
</code></pre>

<p>Does somebody know of a better way to accomplish this?</p>
