I have a situation in which I want to print all the exception caught in catch block using logger.
try {
File file = new File(\"C:\\\\className\").mkdir(
You should probably clarify which logger are you using.
org.apache.commons.logging.Log
interface has method void error(Object message, Throwable t)
(and method void info(Object message, Throwable t)
), which logs the stack trace together with your custom message. Log4J implementation has this method too.
So, probably you need to write:
logger.error("BOOM!", e);
If you need to log it with INFO level (though, it might be a strange use case), then:
logger.info("Just a stack trace, nothing to worry about", e);
Hope it helps.