Module: Occi::Core::Helpers::ErrorHandler

Overview

Introduces additional error handling functions to the receiver class and its instnaces.

Author:

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

:nodoc:


23
24
25
# File 'lib/occi/core/helpers/error_handler.rb', line 23

def self.included(klass)
  klass.extend self
end

Instance Method Details

#handle(klass) ⇒ Object

Wraps potential exceptions raised in the given block in the specified exception class. Internal exception can be later exposed via `Exception#cause`.

Parameters:

  • klass (Class)

    raise error of this class if necessary


13
14
15
16
17
18
19
20
# File 'lib/occi/core/helpers/error_handler.rb', line 13

def handle(klass)
  raise 'You have to provide a block' unless block_given?
  begin
    yield # do whatever you need to do
  rescue => ex
    raise klass, ex.message
  end
end