Class: Byebug::CatchCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/byebug/commands/catchpoint.rb

Constant Summary

Constants inherited from Command

Byebug::Command::DEF_OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

commands, find, format_subcmd, format_subcmds, help, inherited, #initialize, load_commands, #match, method_missing, options, register_setting_get, register_setting_set, register_setting_var, settings, settings_map

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject



41
42
43
44
45
46
47
# File 'lib/byebug/commands/catchpoint.rb', line 41

def description
  %{cat[ch]\t\tsame as "info catch"
    cat[ch] <exception-name> [on|off]
    \tIntercept <exception-name> when there would otherwise be no handler.
    \tWith an "on" or "off", turn handling the exception on or off.
    cat[ch] off\tdelete all catchpoints}
end

.namesObject



37
38
39
# File 'lib/byebug/commands/catchpoint.rb', line 37

def names
  %w(catch)
end

Instance Method Details

#executeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/byebug/commands/catchpoint.rb', line 12

def execute
  excn = @match[1]
  return info_catch unless excn

  if not @match[2]
    if 'off' == @match[1]
      Byebug.catchpoints.clear if
        confirm("Delete all catchpoints? (y or n) ")
    else
      print "Warning #{@match[1]} is not known to be a Class\n" unless
        debug_eval "#{@match[1]}.is_a?(Class)", get_binding
      Byebug.add_catchpoint @match[1]
      print "Catch exception #{@match[1]}.\n"
    end
  elsif @match[2] != 'off'
    errmsg "Off expected. Got #{@match[2]}\n"
  elsif Byebug.catchpoints.member?(@match[1])
    Byebug.catchpoints.delete @match[1]
    print "Catch for exception #{match[1]} removed.\n"
  else
    return errmsg "Catch for exception #{@match[1]} not found\n"
  end
end

#regexpObject



6
7
8
9
10
# File 'lib/byebug/commands/catchpoint.rb', line 6

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