Salome HOME
bf709c3f3471ec576d39ff253bd5342293f34516
[tools/py2cpp.git] / src / Errors.hxx
1 // Copyright (C) 2019  EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #ifndef PY2CPP_ERRORS_HXX
20 #define PY2CPP_ERRORS_HXX
21
22 #include <string>
23 #include <exception>
24 #include <Python.h>
25
26 namespace py2cpp
27 {
28 /*!
29  * Retrieve the last python error and return it as a formated string, containing
30  * the traceback when possible.
31  * After the call of this function, the python error indicator is cleared.
32  * see PyErr_Fetch.
33  */
34 std::string getLastPyError();
35
36 /*!
37  * ConversionCheck class gathers the errors within fromPy functions.
38  */
39 class ConversionCheck
40 {
41 public:
42   ConversionCheck();
43   ConversionCheck(const std::string& error);
44   ~ConversionCheck();
45   operator bool()const; //! true means no error
46   void addError(const std::string& expectedType, PyObject * obj);
47   void addError(const ConversionCheck& err);
48   void addErrorMessage(const std::string& message);
49   void reset(); //! Empty the error message.
50   const std::string& getMessage()const;
51 private:
52   std::string _message;
53 };
54
55 class Exception:public std::exception
56 {
57 public:
58   Exception(const std::string& message);
59   virtual const char* what() const noexcept;
60 private:
61   std::string _message;
62 };
63
64 class ConversionException:public Exception
65 {
66 public:
67   ConversionException(const std::string& message);
68 };
69
70 class ExecutionException:public Exception
71 {
72 public:
73   ExecutionException(const std::string& message);
74 };
75
76 class AttributeException:public Exception
77 {
78 public:
79   AttributeException(const std::string& message);
80 };
81
82 }
83
84 #endif //PY2CPP_ERRORS_HXX