gpt4 book ai didi

ruby - 当你在 ruby​​ 中没有指定异常类时,你会捕获哪些异常?

转载 作者:数据小太阳 更新时间:2023-10-29 08:25:26 26 4
gpt4 key购买 nike

当你没有像这样指定异常类时,你捕获了哪些异常:

begin
# do something
rescue
puts "Exception!"
end

最佳答案

根据我的Programming Ruby 1.9

A rescue clause with no parameter is treated as if it had a parameter of StandardError.

这是来自 ruby-doc.org 的文档:

By default, rescue only intercepts StandardError and its descendants, but you can specify which exceptions you want handled, as arguments. (This technique does not work when rescue is in statement-modifier position.)

为什么不维基 has the Exception hierarchy available如果您需要引用它。

作为快速引用,不是从 StandardError 派生的异常类是:

  • 致命的
  • 没有内存错误
  • 脚本错误
  • 信号异常
  • 系统退出
  • 系统堆栈错误

关于ruby - 当你在 ruby​​ 中没有指定异常类时,你会捕获哪些异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2748515/

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