gpt4 book ai didi

ruby - 使用Ruby,您可以在Begin循环中使用多个救援吗?

转载 作者:行者123 更新时间:2023-12-03 08:54:38 27 4
gpt4 key购买 nike

是否可以在一个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

关于ruby - 使用Ruby,您可以在Begin循环中使用多个救援吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30495883/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com