'Handle exceptions in threaded device jobs.'

def device_job_exception(self, job):

    if isinstance(getattr(job, 'exception', None), UserFeedback):
        ex = job.exception
        func = {UserFeedback.ERROR: error_dialog, UserFeedback.WARNING: warning_dialog, UserFeedback.INFO: info_dialog}[ex.level]
        return func(self, _('Failed'), ex.msg, det_msg=(ex.details if ex.details else ''), show=True)
    try:
        if ('Could    not    read    32    bytes    on    the    control    bus.' in unicode(job.details)):
            error_dialog(self, _('Error    talking    to    device'), _('There    was    a    temporary    error    talking    to    the    device.    Please    unplug    and    reconnect    the    device    or    reboot.')).show()
            return
    except:
        pass
    if (getattr(job, 'exception', None).__class__.__name__ == 'MTPInvalidSendPathError'):
        try:
            from calibre.gui2.device_drivers.mtp_config import SendError
            return SendError(self, job.exception).exec_()
        except:
            traceback.print_exc()
    try:
        prints(job.details, file=sys.stderr)
    except:
        pass
    if (not self.device_error_dialog.isVisible()):
        self.device_error_dialog.set_details(job.details)
        self.device_error_dialog.show()
