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, inherited, #initialize, load_commands, #match, method_missing, options, #print_subcmds, 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

.help(cmd) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/byebug/commands/catchpoint.rb', line 45

def help(cmd)
  %{
    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

.help_commandObject



41
42
43
# File 'lib/byebug/commands/catchpoint.rb', line 41

def help_command
  '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
35
36
37
38
# File 'lib/byebug/commands/catchpoint.rb', line 12

def execute
  excn = @match[1]
  if not excn
    # No args given.
    info_catch
  elsif not @match[2]
    # One arg given.
    if 'off' == excn
      Byebug.catchpoints.clear if
        confirm("Delete all catchpoints? (y or n) ")
    else
      binding = @state.context ? get_binding : TOPLEVEL_BINDING
      unless debug_eval("#{excn}.is_a?(Class)", binding)
        print "Warning #{excn} is not known to be a Class\n"
      end
      Byebug.add_catchpoint(excn)
      print "Catch exception %s.\n", excn
    end
  elsif @match[2] != 'off'
    errmsg "Off expected. Got %s\n", @match[2]
  elsif Byebug.catchpoints.member?(excn)
    Byebug.catchpoints.delete(excn)
    print "Catch for exception %s removed.\n", excn
  else
    errmsg "Catch for exception %s not found.\n", excn
  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