title: Generate a Java stacktrace at any point in the program
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1069066/get-current-stack-trace-in-java">Get current stack trace in Java</a>  </p>
  </blockquote>
  
  
  
  <p>I have a method that saves messages to a file. This method is called from many different parts of my main program. Is there any way that I can generate the stack trace on demand, even though an <code>Exception</code> hasn't been triggered?</p>
  
  <p>For example, I was hoping for something like this...</p>
  
  <pre><code>void saveMsg(String Msg)
  {
    if (a==b) Print Out Where This Method Was Called From [ like stackTrace in exception ]
    else saveMsgToFile(filePath,Msg);
  }
  </code></pre>
  
  <p>I know Java can stack trace in an <code>Exception</code>, but how can I generate the stack trace when no <code>Exception</code> has occurred?</p>