开发者

Rescue RuntimeError in Rake

开发者 https://www.devze.com 2022-12-19 20:28 出处:网络
I have a custom Rakefile which calls different开发者_如何学编程 file tasks. Sometimes a file that is expected doesn\'t exist, and rake throws a RuntimeError and fails. However, I\'d like to do a few t

I have a custom Rakefile which calls different开发者_如何学编程 file tasks. Sometimes a file that is expected doesn't exist, and rake throws a RuntimeError and fails. However, I'd like to do a few things before it fails. So is there any way I could rescue a RuntimeError? Or is there some sort of a magic task which gets called before a complete fail?


I haven't run into this issue with rake myself, but you could try simply wrapping your call to the file tasks in a begin-rescue block, i.e.

begin
  file_task
rescue RuntimeError => e
  puts e
end

and then do your rescuing in the rescue block.

0

精彩评论

暂无评论...
验证码 换一张
取 消