是否可以在開始循環和/或函數中添加多個救援並且每個救援還有下一個救援?使用Ruby,你可以在開始循環中使用多個救援嗎?
例如:
begin twitter_function
rescue Twitter::Error::RateLimit => error
next
rescue Twitter::Error::Unauthorized => error
next
end
是否可以在開始循環和/或函數中添加多個救援並且每個救援還有下一個救援?使用Ruby,你可以在開始循環中使用多個救援嗎?
例如:
begin twitter_function
rescue Twitter::Error::RateLimit => error
next
rescue Twitter::Error::Unauthorized => error
next
end
是的,我們能做到在begin - rescue
循環未來。我們可以按照以下方式做到這一點 -
for i in 1..10
begin
do_something_that_might_raise_exceptions(i)
raise ExpectedError1 => error1
next # do_something_* again, with the next i
raise ExpectedError2 => error2
next # do_something_* again, with the next i
end
end
我們可以在開始時多付一次救援嗎? – marriedjane875
是的,我們可以在開始循環中進行多次救援。 –
你試過了嗎? –
@HunterMcMillen現在就來試試吧,理由就是讓錯誤發生...... – marriedjane875