module Occi::Core::Helpers::ErrorHandler

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

@author Boris Parak <parak@cesnet.cz>

Public Instance Methods

handle(klass) { || ... } click to toggle source

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

@param klass [Class] raise error of this class if necessary

# 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