Added error logging for exceptions