Fix setting exception when task was not executed

There is still an issue of checking whether get_handle() was actually
called on the task. There is no point in setting the exception if there
is no handle as noone will try to retrieve the task result.