Sha256: e2d6941a0a31cdc1e8c22fec86b2ee908ac3e3f3cae71ceda2108e29c640108e

Contents?: true

Size: 973 Bytes

Versions: 7

Compression:

Stored size: 973 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

  class TransmissionError < 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
  when :reader
    IB::TransmissionError.new message
  end
  e.set_backtrace(backtrace) if backtrace
  raise e
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ib-api-972.5 lib/ib/errors.rb
ib-api-972.4 lib/ib/errors.rb
ib-api-972.3.1 lib/ib/errors.rb
ib-api-972.3 lib/ib/errors.rb
ib-api-972.2 lib/ib/errors.rb
ib-api-972.1 lib/ib/errors.rb
ib-api-972.0 lib/ib/errors.rb