處理在下面的代碼中,我想失敗在rescue
異常在Ruby中
puts "Verifying Home Page"
begin
page.find('#logoAnchor')
puts "logo anchor found"
page.find('.navbar-inner')
puts "Header bar found"
page.find('.unstyled')
puts "Found occations frame"
page.find('#easyPrintPromoBox')
puts "Easy Print Frame Found!"
page.find('.tabbable')
puts "3 Tabs Found!"
page.find('#givingCardPromoBox')
puts "Create Frame Found!"
page.find('.footer')
puts "Footer Found!"
rescue
puts "Logo anchor not Found"
end
這裏一切的名單,我只趕上了異常,如果標誌錨不found.I必須捕獲異常如果任何一個他們沒有找到。 爲如:
如果沒有找到標識錨放入rescue
「標誌錨不存在」如果標題欄不存在放入rescue
'rescue'將捕獲拋出的第一個例外。你想獲得一切失敗的清單? – Dogbert
是的,我想得到所有失敗的列表 – chinchu
然後,你必須包裝每一個可以在'begin ... rescue ... end'塊中引發異常的語句。 – Thilo