Flowdock
method

handle_exception

Importance_0
Ruby latest stable (v2_5_5) - 0 notes - Class: IRB::Irb
  • 1_8_6_287
  • 1_8_7_72
  • 1_8_7_330
  • 1_9_1_378
  • 1_9_2_180
  • 1_9_3_125
  • 1_9_3_392
  • 2_1_10
  • 2_2_9
  • 2_4_6
  • 2_5_5
  • 2_6_3 (0)
  • What's this?

Method not available on this version

This method is only available on newer versions. The first available version of the method is shown here.

handle_exception(exc) public

No documentation

This method has no description. You can help the Ruby community by adding new notes.

Hide source
# File lib/irb.rb, line 508
    def handle_exception(exc)
      if exc.backtrace && exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/ &&
         !(SyntaxError === exc)
        irb_bug = true
      else
        irb_bug = false
      end

      if STDOUT.tty?
        attr = ATTR_TTY
        print "#{attr[1]}Traceback#{attr[]} (most recent call last):\n"
      else
        attr = ATTR_PLAIN
      end
      messages = []
      lasts = []
      levels = 0
      if exc.backtrace
        count = 0
        exc.backtrace.each do |m|
          m = @context.workspace.filter_backtrace(m) or next unless irb_bug
          count += 1
          if attr == ATTR_TTY
            m = sprintf("%9d: from %s", count, m)
          else
            m = "\tfrom #{m}"
          end
          if messages.size < @context.back_trace_limit
            messages.push(m)
          elsif lasts.size < @context.back_trace_limit
            lasts.push(m).shift
            levels += 1
          end
        end
      end
      if attr == ATTR_TTY
        unless lasts.empty?
          puts lasts.reverse
          printf "... %d levels...\n", levels if levels > 0
        end
        puts messages.reverse
      end
      m = exc.to_s.split(/\n/)
      print "#{attr[1]}#{exc.class} (#{attr[4]}#{m.shift}#{attr[0, 1]})#{attr[]}\n"
      puts m.map {|s| "#{attr[1]}#{s}#{attr[]}\n"}
      if attr == ATTR_PLAIN
        puts messages
        unless lasts.empty?
          puts lasts
          printf "... %d levels...\n", levels if levels > 0
        end
      end
      print "Maybe IRB bug!\n" if irb_bug
    end
Register or log in to add new notes.