class Exception

Public Instance Methods

detail() click to toggle source

Pretty string output of exception/error object useful for helpful debug messages.

Input: The Exception/StandardError object

Output: The pretty printed string

CREDIT: George Moschovitis

# File lib/core/facets/exception/detail.rb, line 14
def detail
  return %Q{#{self.class.name}: #{message}\n  #{backtrace.join("\n  ")}\n  LOGGED FROM: #{caller[0]}}
end

Public Class Methods

raised?() { || ... } click to toggle source

Does a block raise an a given exception.

# File lib/core/facets/exception/raised.rb, line 5
def self.raised? #:yeild:
  begin
    yield
    false
  rescue self
    true
  end
end
suppress(*exception_classes) { || ... } click to toggle source

Supress errors while executing a block, with execptions.

CREDIT: David Heinemeier Hansson, Thomas Sawyer

# File lib/core/facets/exception/suppress.rb, line 7
def self.suppress(*exception_classes)
  exception_classes.each do |e|
    unless e < self
      raise ArgumentError, "exception #{e} not a subclass of #{self}"
    end
  end
  exception_classes = [self] | exception_classes
  begin
    yield
  rescue Exception => e
    raise unless exception_classes.any? { |cls| e.kind_of?(cls) }
  end
end