module CommandKit::ExceptionHandler
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.message}" exit(1) end
Public Instance Methods
main(argv=[])
click to toggle source
Calls superclass'es `#main` method, but rescues any uncaught exceptions and passes them to {#on_exception}.
@param [Array<String>] argv
The given arguments Array.
@return [Integer]
The exit status of the command.
@api public
Calls superclass method
# File lib/command_kit/exception_handler.rb, line 38 def main(argv=[]) super(argv) rescue Interrupt, Errno::EPIPE => error raise(error) rescue Exception => error on_exception(error) end
on_exception(error)
click to toggle source
Default method for handling when an exception is raised by `#main`.
@param [Exception] error
The raised exception.
@api semipublic
# File lib/command_kit/exception_handler.rb, line 54 def on_exception(error) print_exception(error) exit(1) end