Sha256: 9316c8381d10bf609556c6f2d3e17491e780d27307602494298eaab083828864

Contents?: true

Size: 1.15 KB

Versions: 31

Compression:

Stored size: 1.15 KB

Contents

#This module contains various extra errors used by the other Knj-code.
module Knj::Errors
  #An error that is used when the error is just a notice.
  class Notice < StandardError; end
  
  #An error that specifies that the caller should retry the operation.
  class Retry < StandardError; end
  
  #Returns a string describing the given error. Possible arguments can be given if you want the returned string formatted as HTML.
  #
  #===Examples
  # begin
  #   raise 'test'
  # rescue => e
  #   print Knj::Errors.error_str(e, :html => true)
  # end
  def self.error_str(err, args = {})
    if !err.is_a?(Exception) and err.class.message != "Java::JavaLang::LinkageError"
      raise "Invalid object of class '#{err.class.name}' given."
    end
    
    str = ""
    
    if args[:html]
      str << "<b>#{Knj::Web.html(err.class.name)}</b>: #{Knj::Web.html(err.message)}<br />\n<br />\n"
      
      err.backtrace.each do |bt|
        str << "#{Knj::Web.html(bt)}<br />\n"
      end
      
      str << "<br />\n<br />\n"
    else
      str << "#{err.class.name}: #{err.message}\n\n"
      str << err.backtrace.join("\n")
      str << "\n\n"
    end
    
    return str
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
knjrbfw-0.0.94 lib/knj/errors.rb
knjrbfw-0.0.93 lib/knj/errors.rb
knjrbfw-0.0.92 lib/knj/errors.rb
knjrbfw-0.0.91 lib/knj/errors.rb
knjrbfw-0.0.90 lib/knj/errors.rb
knjrbfw-0.0.89 lib/knj/errors.rb
knjrbfw-0.0.88 lib/knj/errors.rb
knjrbfw-0.0.87 lib/knj/errors.rb
knjrbfw-0.0.86 lib/knj/errors.rb
knjrbfw-0.0.85 lib/knj/errors.rb
knjrbfw-0.0.84 lib/knj/errors.rb
knjrbfw-0.0.83 lib/knj/errors.rb
knjrbfw-0.0.82 lib/knj/errors.rb
knjrbfw-0.0.81 lib/knj/errors.rb
knjrbfw-0.0.80 lib/knj/errors.rb
knjrbfw-0.0.79 lib/knj/errors.rb
knjrbfw-0.0.78 lib/knj/errors.rb
knjrbfw-0.0.77 lib/knj/errors.rb
knjrbfw-0.0.75 lib/knj/errors.rb
knjrbfw-0.0.74 lib/knj/errors.rb