lib/ronin/ui/output/helpers.rb in ronin-support-0.3.0 vs lib/ronin/ui/output/helpers.rb in ronin-support-0.4.0.rc1

- old
+ new

@@ -182,11 +182,11 @@ # @since 0.3.0 # # @api public # def print_warning(*message) - if (Output.verbose? && !(Output.silent?)) + unless Output.silent? Output.handler.print_warning(format_message(message)) return true end return false @@ -216,9 +216,43 @@ Output.handler.print_error(format_message(message)) return true end return false + end + + # + # Prints an exception. + # + # @param [Exception] exception + # The exception to print. + # + # @return [Boolean] + # Specifies whether the exception was printed or not. + # + # @example + # begin + # socket.write(buffer) + # rescue => e + # print_exception(e) + # end + # + # @since 0.4.0 + # + # @api public + # + def print_exception(exception) + return false if Output.silent? + + print_error "#{exception.class}: #{exception.message}" + + if Output.verbose? + exception.backtrace[0,5].each do |line| + print_error " #{line}" + end + end + + return true end protected #