【发布时间】:2018-10-26 06:28:03
【问题描述】:
我在工作人员的模型内部调用了一个方法@txt.watch,在watch() 内部有一个parameters(parameters = self.parameters) 数组。每个参数都有唯一的参考 ID。
我想从工作人员内部拯救每个参数的每个异常错误。
class TextWorker
def perform(id)
@txt = WriteTxt.find(id)
begin
@txt.watch
total_complete_watch = if @txt.job_type == 'movie'
@txt.total_count
else
@txt.tracks.where(status:'complete').size
end
@txt.completed = total_completed_games
@txt.complete = (total_complete_games == @txt.total_count)
@txt.completed_at = Time.zone.now if @txt.complete
@txt.zipper if @txt.complete
@txt.save
FileUtils.rm_rf @txt.base_dir if @txt.complete
rescue StandardError => e
#How to find errors for each reference_id here
raise e
end
end
end
有什么办法吗。非常感谢你。
【问题讨论】:
-
异常一一提出,不收集。
-
如果
@txt.watch在任何阶段抛出错误,您的代码将跳转到调用rescue StandardError => e行。你能分享watch的方法吗?最好在里面做这个。 -
def watch txt = '' self.parameters.each do |parameter| txt += movie_list(参数) end write_list(txt) end
标签: ruby-on-rails ruby exception