Module: CommandKit::ExceptionHandler
Overview
Adds exception handling and printing.
Examples
include CommandKit::Main
include CommandKit::ExceptionHandler
Custom Exception Handling
include CommandKit::Main
include CommandKit::ExceptionHandler
def on_exception(error)
print_error "error: #{error.}"
exit(1)
end
Constant Summary
Constants included from Printing
Instance Method Summary collapse
-
#main(argv = []) ⇒ Integer
Calls superclass'es
#main
method, but rescues any uncaught exceptions and passes them to #on_exception. -
#on_exception(error) ⇒ Object
Default method for handling when an exception is raised by
#main
.
Methods included from Printing
#print_error, #print_exception
Methods included from Stdio
#abort, #gets, #initialize, #print, #printf, #putc, #puts, #readline, #readlines, #stderr, #stdin, #stdout
Instance Method Details
#main(argv = []) ⇒ Integer
Calls superclass'es #main
method, but rescues any uncaught exceptions
and passes them to #on_exception.
40 41 42 43 44 45 46 |
# File 'lib/command_kit/exception_handler.rb', line 40 def main(argv=[]) super(argv) rescue Interrupt, Errno::EPIPE => error raise(error) rescue Exception => error on_exception(error) end |
#on_exception(error) ⇒ Object
Default method for handling when an exception is raised by #main
.
56 57 58 59 |
# File 'lib/command_kit/exception_handler.rb', line 56 def on_exception(error) print_exception(error) exit(1) end |