'Handler called if the task raised an exception.'

def on_failure(self, exc_info, send_failed_event=True, return_ok=False):

    task_ready(self)
    if isinstance(exc_info.exception, MemoryError):
        raise MemoryError((u'Process    got:    %s' % (exc_info.exception,)))
    elif isinstance(exc_info.exception, Reject):
        return self.reject(requeue=exc_info.exception.requeue)
    elif isinstance(exc_info.exception, Ignore):
        return self.acknowledge()
    exc = exc_info.exception
    if isinstance(exc, Retry):
        return self.on_retry(exc_info)
    if isinstance(exc, Terminated):
        self._announce_revoked(u'terminated', True, string(exc), False)
        send_failed_event = False
    elif (isinstance(exc, WorkerLostError) or (not return_ok)):
        self.task.backend.mark_as_failure(self.id, exc, request=self, store_result=self.store_errors)
    if self.task.acks_late:
        requeue = (not self.delivery_info.get(u'redelivered'))
        reject = (self.task.reject_on_worker_lost and isinstance(exc, WorkerLostError))
        if reject:
            self.reject(requeue=requeue)
            send_failed_event = False
        else:
            self.acknowledge()
    if send_failed_event:
        self.send_event(u'task-failed', exception=safe_repr(get_pickled_exception(exc_info.exception)), traceback=exc_info.traceback)
    if (not return_ok):
        error(u'Task    handler    raised    error:    %r', exc, exc_info=exc_info.exc_info)
