Sha256: 2563b61c60277ab724b342d65dffb3f9710e94c8ac33b9260c630e20d8c8425f

Contents?: true

Size: 1.59 KB

Versions: 19

Compression:

Stored size: 1.59 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
  
  #Typically used when an object is not found by the given arguments.
  class NotFound < StandardError; end
  
  #If invalid data was supplied to a list-method or something like it.
  class InvalidData < StandardError; end
  
  #An error that specifies that the caller should retry the operation.
  class Retry < StandardError; end
  
  #The current env does not have access to calling the method.
  class NoAccess < StandardError; end
  
  #The thing you are trying to add already exists or have already been done.
  class Exists < 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

19 entries across 19 versions & 1 rubygems

Version Path
knjrbfw-0.0.59 lib/knj/errors.rb
knjrbfw-0.0.58 lib/knj/errors.rb
knjrbfw-0.0.57 lib/knj/errors.rb
knjrbfw-0.0.55 lib/knj/errors.rb
knjrbfw-0.0.54 lib/knj/errors.rb
knjrbfw-0.0.53 lib/knj/errors.rb
knjrbfw-0.0.52 lib/knj/errors.rb
knjrbfw-0.0.51 lib/knj/errors.rb
knjrbfw-0.0.50 lib/knj/errors.rb
knjrbfw-0.0.49 lib/knj/errors.rb
knjrbfw-0.0.48 lib/knj/errors.rb
knjrbfw-0.0.47 lib/knj/errors.rb
knjrbfw-0.0.46 lib/knj/errors.rb
knjrbfw-0.0.45 lib/knj/errors.rb
knjrbfw-0.0.44 lib/knj/errors.rb
knjrbfw-0.0.43 lib/knj/errors.rb
knjrbfw-0.0.42 lib/knj/errors.rb
knjrbfw-0.0.41 lib/knj/errors.rb
knjrbfw-0.0.40 lib/knj/errors.rb