Exception: DTK::Error

Inherits:
NameError
  • Object
show all
Defined in:
lib/errors/errors.rb

Constant Summary collapse

CallerOffset =
3
DefaultCallerDepth =
3

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg = "", name_or_opts = nil) ⇒ Error

Returns a new instance of Error.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/errors/errors.rb', line 24

def initialize(msg="",name_or_opts=nil)
  name = nil
  opts = Hash.new
  if name_or_opts.kind_of?(Hash)
    opts = name_or_opts
  else
    name = name_or_opts
  end
  super(msg,name)
  #TODO: might make default to be :log_error => false
  unless opts.has_key?(:log_error) and not opts[:log_error]
    if caller_info = opts[:caller_info]
      caller_depth = (caller_info.kind_of?(Hash) ? caller_info[:depth] : nil)||DefaultCallerDepth 
      Log.info_pp(caller[CallerOffset,caller_depth])
    end
  end
end

Class Method Details

.top_error_in_hashObject



21
22
23
# File 'lib/errors/errors.rb', line 21

def self.top_error_in_hash()
  {:error => :Error}
end

Instance Method Details

#to_hashObject



44
45
46
47
48
49
50
51
52
# File 'lib/errors/errors.rb', line 44

def to_hash()
  if to_s == "" 
    Error.top_error_in_hash()
  elsif name.nil?
    {:error => {:Error => {:msg => to_s}}}
  else
    {:error => {name.to_sym => {:msg => to_s}}}
  end
end