Exception: Exception

Defined in:
lib/polyphony/extensions/exception.rb

Overview

Extensions to the Exception class

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Exception

Initializes the exception with the given arguments.



39
40
41
42
# File 'lib/polyphony/extensions/exception.rb', line 39

def initialize(*args)
  @raising_fiber = Fiber.current
  orig_initialize(*args)
end

Class Attribute Details

.__disable_sanitized_backtrace__Object

Set to true to disable sanitizing the backtrace (to remove frames occuring in the Polyphony code itself.)



8
9
10
# File 'lib/polyphony/extensions/exception.rb', line 8

def __disable_sanitized_backtrace__
  @__disable_sanitized_backtrace__
end

Instance Attribute Details

#raising_fiberObject

Set to the fiber from which the exception was raised.



33
34
35
# File 'lib/polyphony/extensions/exception.rb', line 33

def raising_fiber
  @raising_fiber
end

#source_fiberObject

Set to the fiber in which the exception was originally raised (in case the exception was not caught.) The exception will propagate up the fiber tree, allowing it to be caught in any of the fiber's ancestors, while the @source_fiber` attribute will continue pointing to the original fiber.



30
31
32
# File 'lib/polyphony/extensions/exception.rb', line 30

def source_fiber
  @source_fiber
end

Class Method Details

.instantiate(error = nil, message = nil) ⇒ Exception

Creates an exception instance from the given error according to its type.

Parameters:

  • error (nil, String, Class, Exception) (defaults to: nil)

    error

  • message (nil, String) (defaults to: nil)

    error message

Returns:



15
16
17
18
19
20
21
22
23
# File 'lib/polyphony/extensions/exception.rb', line 15

def instantiate(error = nil, message = nil)
  case error
  when String then    RuntimeError.new(error)
  when Array then     error[0].new(error[1])
  when Class then     error.new(message)
  when Exception then error
  else                RuntimeError.new
  end
end

Instance Method Details

#backtraceArray<String>

Returns the backtrace for the exception. If Exception.__disable_sanitized_backtrace__ is not true, any stack frames occuring in Polyphony's code will be removed from the backtrace.

Returns:

  • (Array<String>)

    backtrace



52
53
54
55
56
57
58
59
# File 'lib/polyphony/extensions/exception.rb', line 52

def backtrace
  unless @backtrace_called
    @backtrace_called = true
    return orig_backtrace
  end

  sanitized_backtrace
end

#invokeObject

Raises the exception. this method is a simple wrapper to Kernel.raise. It is overriden in the Polyphony::Interjection exception class.



63
64
65
# File 'lib/polyphony/extensions/exception.rb', line 63

def invoke
  Kernel.raise(self)
end