Class: ExceptionCatchingDelegator

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/akephalos/exception_handling_delegators.rb

Overview

This class can be used to wrap an object so that any exceptions raised by the object’s methods are recued and passed to a specified exception_handler block

Direct Known Subclasses

ExceptionConvertingDelegator

Instance Method Summary collapse

Constructor Details

#initialize(delegate, exception_handler) ⇒ ExceptionCatchingDelegator

  • Args :

    • ++ -> delgate - object to be wrapped

    • ++ -> exception_handler - block to handle rescued exeptions (will be called with yield(exception))



13
14
15
16
# File 'lib/akephalos/exception_handling_delegators.rb', line 13

def initialize(delegate, exception_handler)
  super(delegate)
  @exception_handler = exception_handler
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object

Override of method_missing to rescue exceptions and pass them to the exception_handler



21
22
23
24
25
26
27
# File 'lib/akephalos/exception_handling_delegators.rb', line 21

def method_missing(m, *args, &block)
  begin
    return super(m, *args, &block)
  rescue Exception => exception
    @exception_handler.yield(exception)
  end
end