Added more logging when an exception occurs while processing an exception, and changed ex.printStackTrace() to use log.