[5.0] Log exceptions and their messages when a job fails.

Recreated this pull request for 5.0 instead of 4.2.

Fixes issue #6203.
Shoudl be `catch (Exception $e)` as we got `use Exception;`