'Handle exception.'

def handle_failure(self, task, req, store_errors=True, call_errbacks=True):

    (_, _, tb) = sys.exc_info()
    try:
        exc = self.retval
        einfo = ExceptionInfo()
        einfo.exception = get_pickleable_exception(einfo.exception)
        einfo.type = get_pickleable_etype(einfo.type)
        task.backend.mark_as_failure(req.id, exc, einfo.traceback, request=req, store_result=store_errors, call_errbacks=call_errbacks)
        task.on_failure(exc, req.id, req.args, req.kwargs, einfo)
        signals.task_failure.send(sender=task, task_id=req.id, exception=exc, args=req.args, kwargs=req.kwargs, traceback=tb, einfo=einfo)
        self._log_error(task, req, einfo)
        return einfo
    finally:
        del tb
