Class Informix::Error
In: lib/informix/exceptions.rb
Parent: StandardError

The Error class is the base class for the rest of the exception classes used in this extension. It works as a collection of ExcInfo objects when an error condition occurs.

Methods

[]   add_info   each   length   message   new   size   sql_code   to_s  

Included Modules

Enumerable

Public Class methods

Informix::Error.new([string|array]) => obj

Optional string is the exception message. Optional array must contain only instances of Informix::ExcInfo structs.

Examples: exc = Informix::Error.new arr = [ExcInfo.new(x,y,z…), ExcInfo.new(a,b,c…)] exc = Informix::Error.new(arr)

[Source]

    # File lib/informix/exceptions.rb, line 71
71:     def initialize(v = nil)
72:       case v
73:       when NilClass
74:         @info = []
75:       when String
76:         @info = []
77:         super
78:       when Array
79:         return @info = v if v.all? {|e| ExcInfo === e}
80:         raise(TypeError, "Array may contain only Informix::ExcInfo structs")
81:       else
82:         raise(TypeError,
83:                  "Expected string, or array of Informix::ExcInfo, as argument")
84:       end
85:     end

Public Instance methods

exc[index] => info

Returns the ExcInfo object at index.

[Source]

     # File lib/informix/exceptions.rb, line 118
118:     def [](index)
119:       @info[index]
120:     end

exc.add_info(sql_code, sql_state, class_origin, subclass_origin,

             message, server_name, connection_name)           =>  self

Appends the given information to the exception.

[Source]

    # File lib/informix/exceptions.rb, line 91
91:     def add_info(*v)
92:       v.flatten!
93:       raise(ArgumentError,
94:         "Invalid number of arguments (got %d, need %d)", v.size, 7) \
95:         if v.size != 7
96:       @info.push ExcInfo.new(*v)
97:     end

exc.each {|exc_info| block } => exc_info

Calls block once for each Informix::ExcInfo object in the exception.

[Source]

     # File lib/informix/exceptions.rb, line 111
111:     def each(&block)
112:       @info.each(&block)
113:     end
length()

Alias for size

exc.message => string

Overrides Exception#message. Returns first message in ExcInfo array, or if the array is empty, delegates back to the parent class.

[Source]

     # File lib/informix/exceptions.rb, line 138
138:     def message
139:       @info.size > 0 ? @info[0].message : super
140:     end

exc.size => num

Returns the number of Informix exception messages in the exception.

[Source]

     # File lib/informix/exceptions.rb, line 102
102:     def size
103:       @info.size
104:     end

exc.sqlcode => fixnum

Returns the SQLCODE for the first stored ExcInfo struct, or 0 if none are stored.

[Source]

     # File lib/informix/exceptions.rb, line 146
146:     def sql_code
147:       @info.size > 0 ? @info[0].sql_code : 0
148:     end

exc.to_s => string

Returns a string representation of self.

[Source]

     # File lib/informix/exceptions.rb, line 125
125:     def to_s
126:       return super if @info.size == 0
127:       ret = ""
128:       @info.each do |info|
129:         ret += info.to_s
130:       end
131:       ret
132:     end

[Validate]