Exception: Ragweed::Wraposx::KernelCallError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/ragweed/wraposx/kernelerrorx.rb

Overview

Exception class for mach kernel calls. Works mostly like SystemCallError. Subclasses are individual error conditions and case equality (===) is done by class then error number (KErrno)

Constant Summary collapse

DEFAULT_MESSAGE =
"Unknown Error"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg) ⇒ KernelCallError

Returns a new instance of KernelCallError.



116
117
118
# File 'lib/ragweed/wraposx/kernelerrorx.rb', line 116

def initialize(msg)
  super msg
end

Instance Attribute Details

#kerrnoObject (readonly)

Returns the value of attribute kerrno.



72
73
74
# File 'lib/ragweed/wraposx/kernelerrorx.rb', line 72

def kerrno
  @kerrno
end

Class Method Details

.===(other) ⇒ Object

Case equality. Returns true if self and other are KernelCallError or when error numbers match.



105
106
107
108
109
110
111
112
113
114
# File 'lib/ragweed/wraposx/kernelerrorx.rb', line 105

def self.===(other)
  return false if not other.kind_of?(Ragweed::Wraposx::KernelCallError)
  return true if self == Ragweed::Wraposx::KernelCallError
  
  begin
    return self.const_get("KErrno") == other.const_get("KErrno")
  rescue
    return false
  end
end

.new(msg = "", err = nil) ⇒ Object

Returns a subclass of KernelCallError based on the KernelReturn value err



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/ragweed/wraposx/kernelerrorx.rb', line 75

def self.new(msg = "", err = nil)
  if msg.kind_of? Fixnum
    err = msg
    msg = ""
  end
  mesg = ""

  klass = Ragweed::Wraposx::KErrno.constants.detect{|x| Ragweed::Wraposx::KErrno.const_get(x).const_get("KErrno") == err}
  if (klass.nil? or klass.empty?)
    o = self.allocate
    o.instance_variable_set("@kerrno", err)
    mesg = "Unknown kernel error"
  else
    o = Ragweed::Wraposx::KErrno.const_get(klass).allocate
    mesg = Ragweed::Wraposx::KernelReturn.const_get(klass)[:message]
  end
  
  if o.class.const_defined?("KErrno")
    o.instance_variable_set("@kerrno", o.class.const_get("KErrno"))
  else
    o.instance_variable_set("@kerrno", err)
    mesg = "#{mesg}: #{err}" if err
  end

  mesg = "#{mesg} - #{msg}" if !(msg.nil? or msg.to_s.empty?)  
  o.send(:initialize, mesg)
  return o
end