Rake Task: error handling

2020-08-09 10:26发布

问题:

I am still learning Rake.

Does Rake has built in support to handle task's error like MSBuild of NANT: if this task failed; execute anoter tasks (rolling back, etc.)

e.g.: in MSBuild they have OnError element

<OnError ExecuteTargets="RollBackDatabase" />

Thanks for your help

回答1:

Found out the answer:

just use normal exception handling block

task :will_fail_task do
  begin
    raise "something's wrong here"
  rescue
    rollback()
    raise "error executing task"
  end
end


标签: ruby rake