title: How can I nicely print a formatted exception that I catch in a rescue block?
body: <p>I'm using Rails 5 (Ruby 2.4).  I have a block of code that catches an exception and prints out, what I thought was a stack trace ...</p>
  
  <pre><code>      begin
      ...
        rescue Exception =&gt; e
          errors.push(e)
          puts "#{e.backtrace}"
          raise e
        end
  </code></pre>
  
  <p>Unfortunately what gets printed out is something completely unreadable, like below ...</p>
  
  <pre><code>["/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'"]
  </code></pre>
  
  <p>Is there any way I can get my exception printed out in a nice formatted way, the same way it woudl normally be printed out when it just occurs within Rails?</p>