ruby - 获取导致异常的对象信息
问题描述
我编写了以下代码来处理我的异常。
class Business < ExceptionController
def work(arg1,arg2)
#####some business logic that cause exception
end
end
class ExceptionController < ApplicationController
rescue_from Exception, :with => :render_error_response
def render_error_response(e)
p e.message
p e.backtrace
end
end
render_error_response
我记录异常控制器中定义的消息和回溯。我想打印函数的参数,即arg1
导致异常arg2
的函数的参数。work
除了异常回溯,我还需要调用 def 工作的对象信息。
解决方案
您必须自己装饰异常消息。
class Business < ExceptionController
def work(arg1, arg2)
#####some business logic that cause exception
rescue => ex
ex.message << (" (arg1: %p, arg2: %p, self: %p)" % [arg1, arg2, self])
raise ex
end
end
推荐阅读
- unit-testing - 测试和验证 Angular2+ 构建
- javascript - 根据动态宽度更改进度条的类别
- api - 为现有的烧瓶项目生成 OpenAPI 定义和文档
- julia - Julia 中的单位矩阵
- java - 如何在 RowsFragment 中折叠(隐藏)gridView(仅在行集中时显示)
- angular - 我的 NgRx 效果不起作用,什么也没发生
- sql - 优化导致死锁的查询
- python - 如何确保子类是数据类?
- python - 制作高度定制的、可悬停的、可重叠的小部件
- gradle - 程序类型已经存在:androidx.work.ArrayCreatingInputMerger