簡體   English   中英

使用Ruby,您可以在Begin循環中使用多個救援嗎?

[英]Using Ruby, can you use more than one rescue in a begin loop?

是否可以在一個begin循環和/或一個函數中添加多個救援,並且每個救援還有一個救援?

例如:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM