Class: Byebug::CatchCommand

Inherits:
Command
  • Object
show all
Includes:
Helpers::EvalHelper
Defined in:
lib/byebug/commands/catch.rb

Overview

Implements exception catching.

Enables the user to catch unhandled assertion when they happen.

Instance Attribute Summary

Attributes inherited from Command

#processor

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::EvalHelper

#error_eval, #multiple_thread_eval, #separate_thread_eval, #silent_eval, #warning_eval

Methods inherited from Command

#arguments, columnize, #context, #frame, help, #initialize, match, to_s

Methods included from Helpers::StringHelper

#camelize, #prettify

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/byebug/commands/catch.rb', line 19

def self.description
  <<-EOD
    cat[ch][ (off|<exception>[ off])]

    #{short_description}

    catch                 -- lists catchpoints
    catch off             -- deletes all catchpoints
    catch <exception>     -- enables handling <exception>
    catch <exception> off -- disables handling <exception>
  EOD
end

.regexpObject



15
16
17
# File 'lib/byebug/commands/catch.rb', line 15

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

.short_descriptionObject



32
33
34
# File 'lib/byebug/commands/catch.rb', line 32

def self.short_description
  'Handles exception catchpoints'
end

Instance Method Details

#executeObject



36
37
38
39
40
41
42
43
44
# File 'lib/byebug/commands/catch.rb', line 36

def execute
  return info unless @match[1]

  return 'off' == @match[1] ? clear : add(@match[1]) unless @match[2]

  return errmsg pr('catch.errors.off', off: cmd) unless @match[2] == 'off'

  remove(@match[1])
end