要处理Rails异常,我看到人们“提出SomeException.new”或“提出SomeException”,有什么区别?
说我是否有课
class UnableToCreateShipments < StandardError; end
我能同时做到吗?
raise UnableToCreateShipments
raise UnableToCreateShipments.new
或者留言
raise UnableToCreateShipments, 'my error message'
raise UnableToCreateShipments.new('my error message')
答案 0 :(得分:9)
你可以做到这两点,但是Boris Batsov的Ruby Style Guide和RuboCop建议只传递异常类的简单版本,而不是创建它的实例。