Class: Byebug::CatchCommand
- Defined in:
- lib/byebug/commands/catch.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, #match
Methods included from StringFunctions
Methods included from FileFunctions
#get_line, #get_lines, #n_lines, #normalize
Methods included from ParseFunctions
#get_int, #parse_steps, #syntax_valid?
Constructor Details
This class inherits a constructor from Byebug::Command
Class Method Details
.description ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/byebug/commands/catch.rb', line 52 def description prettify <<-EOD cat[ch][ (off|<exception>[ off])] "catch" lists catchpoints. "catch off" deletes all catchpoints. "catch <exception>" enables handling <exception>. "catch <exception> off" disables handling <exception>. EOD end |
.names ⇒ Object
48 49 50 |
# File 'lib/byebug/commands/catch.rb', line 48 def names %w(catch) end |
Instance Method Details
#execute ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/byebug/commands/catch.rb', line 16 def execute ex = @match[1] return info_catch unless ex cmd = @match[2] unless cmd if 'off' == ex Byebug.catchpoints.clear if confirm(pr('catch.confirmations.delete_all')) return end is_class = bb_eval("#{ex.is_a?(Class)}") puts pr('catch.errors.not_class', class: ex) unless is_class Byebug.add_catchpoint(ex) return puts pr('catch.catching', exception: ex) end if cmd == 'off' exists = Byebug.catchpoints.member?(ex) return errmsg pr('catch.errors.not_found', exception: ex) unless exists Byebug.catchpoints.delete(ex) return errmsg pr('catch.errors.removed', exception: ex) end errmsg pr('catch.errors.off', off: cmd) end |
#regexp ⇒ Object
12 13 14 |
# File 'lib/byebug/commands/catch.rb', line 12 def regexp /^\s* cat(?:ch)? (?:\s+(\S+))? (?:\s+(off))? \s*$/x end |