Sha256: e9d9190217efaa1627b7032cb9afeb6e678b2217e307103dfae907cabb13d7bd

Contents?: true

Size: 921 Bytes

Versions: 1

Compression:

Stored size: 921 Bytes

Contents

class DBStruct

  protected

  # Base class for all exceptions thrown by `DBStruct`.  Also used as
  # the "misc" exception.
  class Failure < RuntimeError; end

  # Exception: malformed or missing column name
  class FieldError < Failure ; end

  # Exception: Wrong type for this field
  class TypeError < Failure ; end

  # Exception: Underlying row is missing
  class MissingRowError < Failure ; end

  private

  # Error checking needs to be global, so we put it in a module and
  # import it everywhere.
  module ErrorHelpers
    
    # Error check: if block evaluates to false, raise a Lite3::DBM::Error
    # with the given message.
    def check(message, exception = Failure, &block)
      return if block && block.call
      raise exception.new(message)
    end

    def oops(msg) raise Failure.new(msg) ; end
  end

  protected

  include ErrorHelpers
  class << self
    include ErrorHelpers
  end
  
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
db-struct-0.1.0 lib/internal/error.rb