Sha256: 2182b7f05b8ec13794737c3250e629bc4b9059694c9474b3e6216fe883ac9315

Contents?: true

Size: 979 Bytes

Versions: 4

Compression:

Stored size: 979 Bytes

Contents

# encoding: utf-8

module Rubymisc
  module Exceptional
    def ASSERT(&block)
      begin
        yield
      rescue Exception => e
        STDERR.puts e.inspect
        STDERR.puts e.backtrace
        # raise e.class, "#{e.message}", caller
      end
    end

    ##
    # @example
    #   begin; raise 'Timeout socket'; rescue errors_with_message(/socket/); p 'socket E'; end
    #
    def errors_with_message(pattern)
      m = Module.new
      (class << m; self; end).instance_eval do
        define_method(:===) do |e|
          pattern === e.message
        end
      end
      m
    end

    ##
    # @example
    #   rescue => e; raise NestedException.new('Error B', e); end
    #   rescue; raise NestedException, 'Error B'; end
    #
    class NestedException < StandardError
      attr :original

      def initialize(msg, original = $!)
        super(msg)
        @original = original
      end
    end
  end
end

::Object.module_eval 'include Rubymisc::Exceptional'

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubymisc-0.0.4 lib/rubymisc/exceptional.rb
rubymisc-0.0.3.3 lib/rubymisc/exceptional.rb
rubymisc-0.0.3.2 lib/rubymisc/exceptional.rb
rubymisc-0.0.3.1 lib/rubymisc/exceptional.rb