本文簡要介紹ruby語言中 StandardError類
的用法。
最標準的錯誤類型是 StandardError
的子類。沒有明確的 Exception
類的救援子句將救援所有StandardErrors(並且隻有那些)。
def foo
raise "Oups"
end
foo rescue "Hello" #=> "Hello"
另一方麵:
require 'does/not/exist' rescue "Hi"
raises the exception:
LoadError: no such file to load -- does/not/exist
相關用法
- Ruby Stat.stat <=>用法及代碼示例
- Ruby Stat.world_writable?用法及代碼示例
- Ruby Stat.birthtime用法及代碼示例
- Ruby Status.to_s用法及代碼示例
- Ruby Stat.ino用法及代碼示例
- Ruby Stat.readable_real?用法及代碼示例
- Ruby Stat.blockdev?用法及代碼示例
- Ruby Stat.grpowned?用法及代碼示例
- Ruby Stat.mode用法及代碼示例
- Ruby Stat.setuid?用法及代碼示例
- Ruby Stat.ftype用法及代碼示例
- Ruby Stat.blocks用法及代碼示例
- Ruby Stat.ctime用法及代碼示例
- Ruby Stat.rdev_major用法及代碼示例
- Ruby Stat.gid用法及代碼示例
- Ruby Stat.world_readable?用法及代碼示例
- Ruby Stat.size用法及代碼示例
- Ruby Stat.atime用法及代碼示例
- Ruby Stat.dev_major用法及代碼示例
- Ruby Stat.writable_real?用法及代碼示例
- Ruby Status.exitstatus用法及代碼示例
- Ruby Stat.dev_minor用法及代碼示例
- Ruby Stat.owned?用法及代碼示例
- Ruby Stat.file?用法及代碼示例
- Ruby Status類用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 StandardError類。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。