Support for the Ruby 2.4 series has ended. See here for reference.

In Files

  • e2mmap.rb

Class/Module Index [+]

Quicksearch

Exception2MessageMapper

Helper module for easily defining exceptions with predefined messages.

Usage

1.

class Foo
  extend Exception2MessageMapper
  def_e2message ExistingExceptionClass, "message..."
  def_exception :NewExceptionClass, "message..."[, superclass]
  ...
end

2.

module Error
  extend Exception2MessageMapper
  def_e2message ExistingExceptionClass, "message..."
  def_exception :NewExceptionClass, "message..."[, superclass]
  ...
end
class Foo
  include Error
  ...
end

foo = Foo.new
foo.Fail ....

3.

module Error
  extend Exception2MessageMapper
  def_e2message ExistingExceptionClass, "message..."
  def_exception :NewExceptionClass, "message..."[, superclass]
  ...
end
class Foo
  extend Exception2MessageMapper
  include Error
  ...
end

Foo.Fail NewExceptionClass, arg...
Foo.Fail ExistingExceptionClass, arg...

Public Instance Methods

Fail(err = nil, *rest) click to toggle source
Alias for: Raise
Raise(err = nil, *rest) click to toggle source

Fail(err, *rest)

err:    exception
rest:   message arguments
 
               # File e2mmap.rb, line 85
def Raise(err = nil, *rest)
  E2MM.Raise(self, err, *rest)
end
            
Also aliased as: Fail, fail
bind(cl) click to toggle source
 
               # File e2mmap.rb, line 64
  def bind(cl)
    self.module_eval "#{<<-"begin;"}\n#{<<-"end;"}", __FILE__, __LINE__+1
    begin;
      def Raise(err = nil, *rest)
        Exception2MessageMapper.Raise(self.class, err, *rest)
      end
      alias Fail Raise

      class << self
        undef included
      end
      def self.included(mod)
        mod.extend Exception2MessageMapper
      end
    end;
  end
            
def_e2message(c, m) click to toggle source

def_e2message(c, m)

    c:  exception
    m:  message_form
define exception c with message m.
 
               # File e2mmap.rb, line 96
def def_e2message(c, m)
  E2MM.def_e2message(self, c, m)
end
            
def_exception(n, m, s = StandardError) click to toggle source

def_exception(n, m, s)

    n:  exception_name
    m:  message_form
    s:  superclass(default: StandardError)
define exception named ``c'' with message m.
 
               # File e2mmap.rb, line 106
def def_exception(n, m, s = StandardError)
  E2MM.def_exception(self, n, m, s)
end
            
fail(err = nil, *rest) click to toggle source
Alias for: Raise