I have a method which has to catch an exception. There was bug in the production and when I was going through the log file I found something strange. There seems to be an exception, when I searched for the catch block where I printed exception object by implementing toString(), I found that the object printed as null. I found 2 or 3 links but there’s never a clear answer. Below is my method and logger.
public void downloadFile() throws ServletException, IOException { try{ //some logic to download a file } catch(Exception e) { setRetMessage("File cannot be download."); PAYTFFileDebug.trace("Error in download >>>>>>>>> "+e.toString(),PAYTFFileDebug.LEVEL_5); } }
below is the log in which i found something which is not usual.
Fri Jan 27 14:50:13 GMT+05:30 2015 : Level 5:Error in download >>>>>>>>> null
Answer
Typically you would want to log the stack trace of the Exception. I cannot tell which underlying logging framework you are using but most would allow you to pass a Throwable after the message. For example in Log4J we have:
public void error(Object message, Throwable t)
If your logging framework supports it can you try:
PAYTFFileDebug.error("Error in download.", e);
This will ensure that you log the complete stack trace of that exception and can then better troubleshoot the problem.