File: exceptions.hpp

package info (click to toggle)
mariadb-10.0 10.0.32-0%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 476,064 kB
  • sloc: cpp: 1,400,131; ansic: 832,140; perl: 54,391; sh: 41,304; pascal: 32,365; yacc: 14,921; xml: 5,257; sql: 4,667; cs: 4,647; makefile: 4,555; ruby: 4,465; python: 2,292; lex: 1,427; java: 941; asm: 295; awk: 54; php: 22; sed: 16
file content (152 lines) | stat: -rw-r--r-- 5,001 bytes parent folder | download | duplicates (6)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#ident "$Id$"
/*======
This file is part of PerconaFT.


Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.

    PerconaFT is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License, version 2,
    as published by the Free Software Foundation.

    PerconaFT is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with PerconaFT.  If not, see <http://www.gnu.org/licenses/>.

----------------------------------------

    PerconaFT is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License, version 3,
    as published by the Free Software Foundation.

    PerconaFT is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with PerconaFT.  If not, see <http://www.gnu.org/licenses/>.
======= */

#ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved."

#pragma once

#include <exception>
#include <string.h>

#include <db.h>

namespace ftcxx {

    class ft_exception : public std::exception {
        int _code;

        static const char *ft_strerror(int code) {
            switch (code) {
            case DB_RUNRECOVERY:
                return "DB_RUNRECOVERY";
            case DB_KEYEXIST:
                return "DB_KEYEXIST";
            case DB_LOCK_DEADLOCK:
                return "DB_LOCK_DEADLOCK";
            case DB_LOCK_NOTGRANTED:
                return "DB_LOCK_NOTGRANTED";
            case DB_NOTFOUND:
                return "DB_NOTFOUND";
            case DB_SECONDARY_BAD:
                return "DB_SECONDARY_BAD";
            case DB_DONOTINDEX:
                return "DB_DONOTINDEX";
            case DB_BUFFER_SMALL:
                return "DB_BUFFER_SMALL";
            case DB_BADFORMAT:
                return "DB_BADFORMAT";
            case TOKUDB_OUT_OF_LOCKS:
                return "TOKUDB_OUT_OF_LOCKS";
            case TOKUDB_SUCCEEDED_EARLY:
                return "TOKUDB_SUCCEEDED_EARLY";
            case TOKUDB_FOUND_BUT_REJECTED:
                return "TOKUDB_FOUND_BUT_REJECTED";
            case TOKUDB_USER_CALLBACK_ERROR:
                return "TOKUDB_USER_CALLBACK_ERROR";
            case TOKUDB_DICTIONARY_TOO_OLD:
                return "TOKUDB_DICTIONARY_TOO_OLD";
            case TOKUDB_DICTIONARY_TOO_NEW:
                return "TOKUDB_DICTIONARY_TOO_NEW";
            case TOKUDB_DICTIONARY_NO_HEADER:
                return "TOKUDB_DICTIONARY_NO_HEADER";
            case TOKUDB_CANCELED:
                return "TOKUDB_CANCELED";
            case TOKUDB_NO_DATA:
                return "TOKUDB_NO_DATA";
            case TOKUDB_ACCEPT:
                return "TOKUDB_ACCEPT";
            case TOKUDB_MVCC_DICTIONARY_TOO_NEW:
                return "TOKUDB_MVCC_DICTIONARY_TOO_NEW";
            case TOKUDB_UPGRADE_FAILURE:
                return "TOKUDB_UPGRADE_FAILURE";
            case TOKUDB_TRY_AGAIN:
                return "TOKUDB_TRY_AGAIN";
            case TOKUDB_NEEDS_REPAIR:
                return "TOKUDB_NEEDS_REPAIR";
            case TOKUDB_CURSOR_CONTINUE:
                return "TOKUDB_CURSOR_CONTINUE";
            case TOKUDB_BAD_CHECKSUM:
                return "TOKUDB_BAD_CHECKSUM";
            case TOKUDB_HUGE_PAGES_ENABLED:
                return "TOKUDB_HUGE_PAGES_ENABLED";
            case TOKUDB_OUT_OF_RANGE:
                return "TOKUDB_OUT_OF_RANGE";
            case TOKUDB_INTERRUPTED:
                return "TOKUDB_INTERRUPTED";
            default:
                return "unknown ft error";
            }
        }

    public:
        ft_exception(int c) : _code(c) {}

        int code() const noexcept {
            return _code;
        }

        virtual const char *what() const noexcept {
            return ft_strerror(_code);
        }
    };

    class system_exception : public std::exception {
        int _code;

    public:
        system_exception(int c) : _code(c) {}

        int code() const noexcept {
            return _code;
        }

        virtual const char *what() const noexcept {
            return strerror(_code);
        }
    };

    inline void handle_ft_retval(int r) {
        if (r == 0) {
            return;
        }
        if (r < 0) {
            throw ft_exception(r);
        }
        if (r > 0) {
            throw system_exception(r);
        }
    }

} // namespace ftcxx