Updated copyrights
[libdai.git] / include / dai / exceptions.h
1 /* Copyright (C) 2006-2008 Joris Mooij [joris dot mooij at tuebingen dot mpg dot de]
2 Radboud University Nijmegen, The Netherlands /
3 Max Planck Institute for Biological Cybernetics, Germany
4
5 This file is part of libDAI.
6
7 libDAI is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 libDAI is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with libDAI; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22
23 #ifndef __defined_libdai_exceptions_h
24 #define __defined_libdai_exceptions_h
25
26
27 #include <exception>
28 #include <stdexcept>
29 #include <string>
30
31
32 #define DAI_QUOTE(x) #x
33 #define DAI_TOSTRING(x) DAI_QUOTE(x)
34
35 #define DAI_THROW(cod) throw dai::Exception(dai::Exception::cod, std::string(__FILE__ ", line " DAI_TOSTRING(__LINE__)))
36
37
38 namespace dai {
39
40
41 class Exception : public std::runtime_error {
42 public:
43 Exception(size_t code, const std::string& msg = "") : std::runtime_error(ErrorStrings[code] + " [" + msg + "]") {}
44
45 enum {NOT_IMPLEMENTED,
46 UNKNOWN_DAI_ALGORITHM,
47 UNKNOWN_PROPERTY_TYPE,
48 MALFORMED_PROPERTY,
49 UNKNOWN_ENUM_VALUE,
50 CANNOT_READ_FILE,
51 CANNOT_WRITE_FILE,
52 INVALID_FACTORGRAPH_FILE,
53 NOT_ALL_PROPERTIES_SPECIFIED,
54 MULTIPLE_UNDO,
55 FACTORGRAPH_NOT_CONNECTED,
56 IMPOSSIBLE_TYPECAST,
57 INTERNAL_ERROR,
58 NUM_ERRORS}; // NUM_ERRORS should be the last entry
59
60 private:
61 static std::string ErrorStrings[NUM_ERRORS];
62 };
63
64
65 }
66
67
68 #endif