Sha256: d8f19c611421098ffed12c2d3b2fadea2bf61bbf940b62b98dcf8344e2895357

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

module Debugger
  class CatchCommand < Command # :nodoc:
    self.control = true

    def regexp
      /^\s* cat(?:ch)? 
           (?:\s+ (\S+))? 
           (?:\s+ (off))? \s* $/ix
    end

    def execute
      excn = @match[1] 
      if not excn
        # No args given.
        errmsg "Exception class must be specified for 'catch' command"
      elsif not @match[2]
        # One arg given.
        if 'off' == excn
          clear_catchpoints
        else
          Debugger.add_catchpoint(excn)
          print_catchpoint_set(excn)
        end
      elsif @match[2] != 'off'
        errmsg "Off expected. Got %s\n", @match[2]
      elsif remove_catchpoint(excn)
        print_catchpoint_deleted(excn)
      else
        errmsg "Catch for exception %s not found.\n", excn
      end
    end

    class << self
      def help_command
        'catch'
      end

      def help(cmd)
        %{
          cat[ch]\t\t\tshow catchpoint
          cat[ch] off \tremove all catch points
          cat[ch] <an Exception>\tset catchpoint to an exception
          cat[ch] <an Exception> off \tremove catchpoint for an exception
        }
      end
    end

    private

    def clear_catchpoints
      if Debugger.respond_to?(:clear_catchpoints)
        Debugger.clear_catchpoints
      else
        Debugger.catchpoints.clear
      end
    end

    def remove_catchpoint(excn)
      return Debugger.remove_catchpoint(excn) if Debugger.respond_to?(:remove_catchpoint)
      return Debugger.catchpoints.delete(excn) if Debugger.catchpoints.member?(excn)
      false
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby-debug-ide22-0.7.4 lib/ruby-debug-ide/commands/catchpoint.rb