1 | /* |
2 | exception.h - exception wrapping a gpgme error |
3 | Copyright (C) 2007 Klarälvdalens Datakonsult AB |
4 | |
5 | This file is part of GPGME++. |
6 | |
7 | GPGME++ is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. |
11 | |
12 | GPGME++ 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 Library General Public License for more details. |
16 | |
17 | You should have received a copy of the GNU Library General Public License |
18 | along with GPGME++; see the file COPYING.LIB. If not, write to the |
19 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 | Boston, MA 02110-1301, USA. |
21 | */ |
22 | |
23 | // -*- c++ -*- |
24 | #ifndef __GPGMEPP_EXCEPTION_H__ |
25 | #define __GPGMEPP_EXCEPTION_H__ |
26 | |
27 | #include <gpgme++/error.h> |
28 | |
29 | #include <stdexcept> |
30 | #include <string> |
31 | |
32 | namespace GpgME { |
33 | |
34 | class GPGMEPP_EXPORT Exception : public std::runtime_error { |
35 | public: |
36 | enum Options { |
37 | NoOptions = 0x0, |
38 | MessageOnly = 0x1, |
39 | |
40 | AllOptions = MessageOnly |
41 | }; |
42 | |
43 | explicit Exception( const GpgME::Error & err, const std::string & msg=std::string(), Options opt=NoOptions ) |
44 | : std::runtime_error( make_message( err, msg, opt ) ), m_error( err ), m_message( msg ) {} |
45 | |
46 | ~Exception() throw(); |
47 | |
48 | Error error() const { |
49 | return m_error; |
50 | } |
51 | const std::string & message() const { |
52 | return m_message; |
53 | } |
54 | private: |
55 | static std::string make_message( const GpgME::Error & err, const std::string & msg ); |
56 | static std::string make_message( const GpgME::Error & err, const std::string & msg, Options opt ); |
57 | private: |
58 | const GpgME::Error m_error; |
59 | const std::string m_message; |
60 | }; |
61 | |
62 | } // namespace GpgME |
63 | |
64 | #endif /* __GPGMEPP_EXCEPTION_H__ */ |
65 | |