Method to log exceptions