Exception: PyBind::PyError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/pybind/error.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, value, traceback) ⇒ PyError

Returns a new instance of PyError.



16
17
18
19
20
21
# File 'lib/pybind/error.rb', line 16

def initialize(type, value, traceback)
  @type = type
  @value = value
  @traceback = traceback
  super("#{type}: #{value}")
end

Instance Attribute Details

#tracebackObject (readonly)

Returns the value of attribute traceback.



23
24
25
# File 'lib/pybind/error.rb', line 23

def traceback
  @traceback
end

#typeObject (readonly)

Returns the value of attribute type.



23
24
25
# File 'lib/pybind/error.rb', line 23

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



23
24
25
# File 'lib/pybind/error.rb', line 23

def value
  @value
end

Class Method Details

.fetchObject



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/pybind/error.rb', line 3

def self.fetch
  ptrs = FFI::MemoryPointer.new(:pointer, 3)
  ptype      = ptrs + 0 * ptrs.type_size
  pvalue     = ptrs + 1 * ptrs.type_size
  ptraceback = ptrs + 2 * ptrs.type_size
  LibPython.PyErr_Fetch(ptype, pvalue, ptraceback)
  LibPython.PyErr_NormalizeException(ptype, pvalue, ptraceback)
  type = TypeCast.from_python(PyObjectStruct.new(ptype.read(:pointer)))
  value = TypeCast.from_python(PyObjectStruct.new(pvalue.read(:pointer)))
  traceback = TypeCast.from_python(PyObjectStruct.new(ptraceback.read(:pointer)))
  new(type, value, traceback)
end

Instance Method Details

#messageObject



25
26
27
28
29
30
31
# File 'lib/pybind/error.rb', line 25

def message
  baseline = super
  lines = [baseline] + PyBind.parse_traceback(traceback)
  lines.join("\n")
rescue
  baseline
end