File: exceptions.rb

package info (click to toggle)
libdbi-ruby 0.4.3-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 472 kB
  • ctags: 619
  • sloc: ruby: 4,583; makefile: 62; perl: 12
file content (65 lines) | stat: -rw-r--r-- 2,149 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
module DBI
    #  Exceptions (borrowed by Python API 2.0)

    # Base class of all other error exceptions.  Use this to catch all DBI
    # errors.
    class Error < RuntimeError
    end

    # For important warnings like data truncation, etc.
    class Warning < RuntimeError
    end

    # Exception for errors related to the DBI interface rather than the
    # database itself.
    class InterfaceError < Error
    end

    # Exception raised if the DBD driver has not specified a mandatory method.
    class NotImplementedError < InterfaceError
    end

    # Exception for errors related to the database.
    class DatabaseError < Error
        attr_reader :err, :errstr, :state

        def initialize(errstr="", err=nil, state=nil)
            super(errstr)
            @err, @errstr, @state = err, errstr, state
        end
    end

    # Exception for errors due to problems with the processed 
    # data such as division by zero, numeric value out of range, etc.
    class DataError < DatabaseError
    end

    # Exception for errors related to the database's operation which are not
    # necessarily under the control of the programmer.  This includes such
    # things as unexpected disconnect, datasource name not found, transaction
    # could not be processed, a memory allocation error occured during
    # processing, etc.
    class OperationalError < DatabaseError
    end

    # Exception raised when the relational integrity of the database
    # is affected, e.g. a foreign key check fails.
    class IntegrityError < DatabaseError
    end

    # Exception raised when the database encounters an internal error, 
    # e.g. the cursor is not valid anymore, the transaction is out of sync.
    class InternalError < DatabaseError
    end

    # Exception raised for programming errors, e.g. table not found
    # or already exists, syntax error in SQL statement, wrong number
    # of parameters specified, etc.
    class ProgrammingError < DatabaseError
    end

    # Exception raised if e.g. commit() is called for a database which do not
    # support transactions.
    class NotSupportedError < DatabaseError
    end
end