Added logging in case of exception

Before was a simple "printStackTrace". I changed to log4j error logging