Class: Byebug::CatchCommand
- Defined in:
- lib/byebug/commands/catchpoint.rb
Overview
Implements exception catching.
Enables the user to catch unhandled assertion when they happen.
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Command
commands, find, format_subcmd, format_subcmds, help, inherited, #initialize, load_commands, #match
Constructor Details
This class inherits a constructor from Byebug::Command
Class Method Details
.description ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/byebug/commands/catchpoint.rb', line 43 def description %(cat[ch][ (off|<exception>[ off])] "catch" lists catchpoints. "catch off" deletes all catchpoints. "catch <exception>" enables handling <exception>. "catch <exception> off" disables handling <exception>.) end |
.names ⇒ Object
39 40 41 |
# File 'lib/byebug/commands/catchpoint.rb', line 39 def names %w(catch) end |
Instance Method Details
#execute ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/byebug/commands/catchpoint.rb', line 14 def execute excn = @match[1] return info_catch unless excn if !@match[2] if 'off' == @match[1] Byebug.catchpoints.clear if confirm('Delete all catchpoints? (y or n) ') else puts "Warning #{@match[1]} is not known to be a Class" unless bb_eval "#{@match[1]}.is_a?(Class)", get_binding Byebug.add_catchpoint @match[1] puts "Catching exception #{@match[1]}." end elsif @match[2] != 'off' errmsg "Off expected. Got #{@match[2]}" elsif Byebug.catchpoints.member?(@match[1]) Byebug.catchpoints.delete @match[1] errmsg "Catch for exception #{match[1]} removed" else errmsg "Catch for exception #{@match[1]} not found" end end |
#regexp ⇒ Object
10 11 12 |
# File 'lib/byebug/commands/catchpoint.rb', line 10 def regexp /^\s* cat(?:ch)? (?:\s+(\S+))? (?:\s+(off))? \s*$/x end |