Sha256: 1ef02938f40f80c785a03c177e0c520fa1a60f419579e2d871a0432aad1f3ff3

Contents?: true

Size: 873 Bytes

Versions: 7

Compression:

Stored size: 873 Bytes

Contents

module IB

  # Error handling
  class Error < RuntimeError
  end

  class ArgumentError < ArgumentError
  end

  class SymbolError < ArgumentError
  end

  class LoadError < LoadError
  end

  class FlexError < RuntimeError
  end

end # module IB

# Patching Object with universally accessible top level error method. 
# The method is used throughout the lib instead of plainly raising exceptions. 
# This allows lib user to easily inject user-specific error handling into the lib 
# by just replacing Object#error method.
def error message, type=:standard, backtrace=nil
  e = case type
  when :standard
    IB::Error.new message
  when :args
    IB::ArgumentError.new message
  when :symbol
    IB::SymbolError.new message
  when :load
    IB::LoadError.new message
  when :flex
    IB::FlexError.new message
  end
  e.set_backtrace(backtrace) if backtrace
  raise e
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
my-ib-api-0.0.4 lib/ib/errors.rb
my-ib-api-0.0.3 lib/ib/errors.rb
my-ib-api-0.0.2 lib/ib/errors.rb
my-ib-api-0.0.1 lib/ib/errors.rb
ib-ruby-0.9.2 lib/ib/errors.rb
ib-ruby-0.9.1 lib/ib/errors.rb
ib-ruby-0.9.0 lib/ib/errors.rb