What is the best way to set something to do when a Rake task fails?

I'd like something like:

task :migrate_safely => [:backup, :migrate] do
  rescue
    if :backup
      :restore
    end
  end
end

Is there a way to do anything similar?