Raise custom Exception with arguments

前端 未结 6 1813
礼貌的吻别
礼貌的吻别 2020-12-23 13:36

I\'m defining a custom Exception on a model in rails as kind of a wrapper Exception: (begin[code]rescue[raise custom exception]end)

When I raise the Exc

6条回答
  •  眼角桃花
    2020-12-23 14:07

    You can create an new instance of your Exception subclass, then raise that. For instance:

    begin
      # do something
    rescue => e
      error = MyException.new(e, 'some info')
      raise error
    end
    

提交回复
热议问题