[5.0] Log Exceptions When A Job Fails

Recreated this pull request for 5.0 instead of 4.2.

Fixes issue #6203.
Ping @milesj.