Cuprum

An opinionated implementation of the Command pattern for Ruby applications. Cuprum wraps your business logic in a consistent, object-oriented interface and features status and error management, composability and control flow management.

Module: Cuprum::ExceptionHandling

Parent Namespace
Cuprum
Defined In
lib/cuprum/exception_handling.rb

Table Of Contents

Overview

Utility module for handling uncaught exceptions in commands.

Examples

class UnsafeCommand < Cuprum::Command
  private

  def process
    raise 'Something went wrong.'
  end
end

class SafeCommand < UnsafeCommand
  include Cuprum::ExceptionHandling
end

UnsafeCommand.new.call
#=> raises a StandardError

result = SafeCommand.new.call
#=> a Cuprum::Result
result.error
#=> a Cuprum::Errors::UncaughtException error.
result.error.message
#=> 'uncaught exception in SafeCommand -' \
#   ' StandardError: Something went wrong.'

Back To Top

Instance Methods

#call(*args, **kwargs, &block) => Cuprum::Result

Wraps the #call method with a rescue clause matching any StandardError.

If a StandardError or subclass thereof is raised and not caught by #call, then ExceptionHandling will rescue the exception and return a failing Cuprum::Result with a Cuprum::Errors::UncaughtException error.

Returns

See Also

Back To Top


Back to Documentation | Versions | 1.2 | Reference | Cuprum