begin ... rescue Exception => e errors.push(e) puts "#{e.backtrace}" raise e end
不幸的是,打印出来的东西是完全不可读的,如下所示……
["/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:202:in `block in wait_poll'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:193:in `loop'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:193:in `wait_poll'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:154:in `internal_poll'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:278:in `internal_poll'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:148:in `block in poll'","/Users/nataliab/.rvm/rubIEs/ruby-2.4.0/lib/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:158:in `synchronize'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:148:in `poll'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:717:in `acquire_connection'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:490:in `checkout'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:364:in `connection'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:883:in `retrIEve_connection'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/connection_handling.rb:128:in `retrIEve_connection'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/connection_handling.rb:91:in `connection'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/relation/delegation.rb:43:in `connection'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/relation/query_methods.rb:105:in `bound_attributes'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/relation.rb:702:in `exec_querIEs'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/relation.rb:583:in `load'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/relation.rb:260:in `records'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/relation/finder_methods.rb:527:in `find_take'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/relation/finder_methods.rb:100:in `take'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/relation/finder_methods.rb:78:in `find_by'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/querying.rb:7:in `find_by'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/core.rb:187:in `find_by'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/activerecord-5.0.2/lib/active_record/dynamic_matchers.rb:65:in `find_by_name_and_day_and_user_ID_and_distance_and_distance_unit_ID'","/Users/nataliab/documents/workspace/myproject/app/services/abstract_import_service.rb:71:in `process_event_data'","/Users/nataliab/documents/workspace/myproject/app/services/running_in_the_usa_event_finder_service.rb:265:in `process_generic_event_link'","/Users/nataliab/documents/workspace/myproject/app/services/running_in_the_usa_event_finder_service.rb:118:in `process_event_link'","/Users/nataliab/documents/workspace/myproject/app/services/abstract_event_finder_service.rb:37:in `block (2 levels) in process_data'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:348:in `run_task'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:337:in `block (3 levels) in create_worker'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:320:in `loop'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:320:in `block (2 levels) in create_worker'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:319:in `catch'","/Users/nataliab/.rvm/gems/ruby-2.4.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:319:in `block in create_worker'"]
有没有什么方法可以让我的异常以一种很好的格式化方式打印出来,就像它在Rails中发生时通常打印出来一样?
解决方法 尝试记录这样的异常消息:begin ...rescue Exception => e logger.error e.message e.backtrace.each { |line| logger.error line }end总结
以上是内存溢出为你收集整理的ruby-on-rails – 如何很好地打印我在救援块中捕获的格式化异常?全部内容,希望文章能够帮你解决ruby-on-rails – 如何很好地打印我在救援块中捕获的格式化异常?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)