# File lib/pry/pry_instance.rb, line 456
  def last_exception=(ex)
    class << ex
      attr_accessor :file, :line, :bt_index
      def bt_source_location_for(index)
        backtrace[index] =~ /(.*):(\d+)/
        [$1, $2.to_i]
      end

      def inc_bt_index
        @bt_index = (@bt_index + 1) % backtrace.size
      end
    end

    ex.bt_index = 0
    ex.file, ex.line = ex.bt_source_location_for(0)

    @last_result_is_exception = true
    @output_array << ex
    @last_exception = ex
  end