1 /*
2  * Copyright (C) 2018 Codership Oy <info@codership.com>
3  *
4  * This file is part of wsrep-lib.
5  *
6  * Wsrep-lib is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * Wsrep-lib is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with wsrep-lib.  If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef WSREP_EXCEPTION_HPP
21 #define WSREP_EXCEPTION_HPP
22 
23 #include <stdexcept>
24 #include <cstdlib>
25 
26 namespace wsrep
27 {
28     extern bool abort_on_exception;
29 
30     class runtime_error : public std::runtime_error
31     {
32     public:
runtime_error(const char * msg)33         runtime_error(const char* msg)
34             : std::runtime_error(msg)
35         {
36             if (abort_on_exception)
37             {
38                 ::abort();
39             }
40         }
41 
runtime_error(const std::string & msg)42         runtime_error(const std::string& msg)
43             : std::runtime_error(msg)
44         {
45             if (abort_on_exception)
46             {
47                 ::abort();
48             }
49         }
50     };
51 
52     class not_implemented_error : public std::exception
53     {
54     public:
not_implemented_error()55         not_implemented_error()
56             : std::exception()
57         {
58             ::abort();
59         }
60     };
61 
62     class fatal_error : public std::exception
63     {
64     };
65 }
66 
67 
68 #endif // WSREP_EXCEPTION_HPP
69