2016-08-04 60 views
0

是否有可能在調用API時引發異常(如果有),然後退出發生異常的方法並繼續正常調用其他方法?例如,在情況是這樣的:API錯誤時退出方法並繼續使用其他方法

Class1.first_method 
Class2.second_method -> failed because of an API error 
Clas3.third_method - I want this one to continue 

回答

1
Class1.first_method 

begin 
    Class2.second_method 
rescue StandardError => e 
    $stderr << "An error occurred: #{e.message}" 
end 

Clas3.third_method 

這是一個救援塊,其是這樣的紅寶石的一部分的示例允許Exception handling