Returning (early) from a task

Wanted to get some good programming advice on this…

I’ve got a handful of tasks that all call value_OK() at the beginning. The function returns a pass/fail, which I use to call reject_value, and then return. Could I roll reject_value() and return into the value_OK() function? Can a function cause the calling task to exit; perhaps it’s a bad idea!

task do_something1(uint32_t value);

  if (!value_OK(value)) begin
    reject_value();
    return;
  end

  ....

endtask
task do_something2(uint32_t value);

  if (!value_OK(value)) begin
    reject_value();
    return;
  end

  ....
endtask
task do_something2(uint32_t value);

  if (!value_OK(value)) begin
    reject_value();
    return;
  end

  ....

endtask

In reply to bmorris:

Unfortunately
return
only goes back one level of the call stack. You might think about restructuring your code not to need a return.

task do_something1(uint32_t value);

if (value_OK(value)) begin
   ...
  end
  else
    reject_value();
endtask

If you change reject_value() into a function that always returns 0, you can use short-circuiting

task do_something1(uint32_t value);
if (value_OK(value) || reject_value()) begin
   ...
end
endtask