Possible Duplicate:
Get current stack trace in Java
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 Exception
hasn't been triggered?
For example, I was hoping for something like this...
void saveMsg(String Msg)
{
if (a==b) Print Out Where This Method Was Called From [ like stackTrace in exception ]
else saveMsgToFile(filePath,Msg);
}
I know Java can stack trace in an Exception
, but how can I generate the stack trace when no Exception
has occurred?