You use rescue and read this chapter about Ruby Exceptions [1].
Good luck!
[1] http://www.rubycentral.com/pickaxe/tut_exceptions.html