Module: Knj::Errors

Defined in:
lib/knj/errors.rb

Overview

This module contains various extra errors used by the other Knj-code.

Defined Under Namespace

Classes: Notice, Retry

Class Method Summary collapse

Class Method Details

.error_str(err, args = {}) ⇒ Object

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



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/knj/errors.rb', line 17

def self.error_str(err, args = {})
  if !err.is_a?(Exception) and err.class.name != "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