In ant i can pass an custom ant task as a parameter to an another custom ant task and i can perform/execute the passed ant task. The sample ant custom task code looks something like this.

public class MyGenericCustomTask extents Task implements TaskContainer {
private Task task;
boolean isSerious = false;

@Override
public void addTask(Task arg0) {
 this.task = arg0;
}

public void setIsSerious(boolean b) {
        this.isSerious = b;
}

@Override
public void execute() throws BuildException {
 try {
      this.task.perform(); // If there is a exception
 }catch(BuildException e) {
   if(isSerious) {
     println("Failure is series");
   }
   else {
     println("Log the failure and Continue for this run.");
  }
 } 
} 

How do i achieve the same in gradle custom task ?