1/*
2 exception.cpp - 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#include "exception.h"
25
26#include <gpgme.h>
27
28#include <sstream>
29
30using namespace GpgME;
31using namespace std; // only safe b/c it's so small a file!
32
33Exception::~Exception() throw() {}
34
35// static
36string Exception::make_message( const Error & err, const string & msg ) {
37 return make_message( err, msg, NoOptions );
38}
39
40// static
41string Exception::make_message( const Error & err, const string & msg, Options opt ) {
42 if ( opt & MessageOnly ) {
43 return msg;
44 }
45 char error_string[128];
46 error_string[0] = '\0';
47 gpgme_strerror_r( err.encodedError(), error_string, sizeof error_string );
48 error_string[sizeof error_string - 1] = '\0';
49 stringstream ss;
50 ss << gpgme_strsource( err.encodedError() ) << ": ";
51 if ( !msg.empty() ) {
52 ss << msg << ": ";
53 }
54 ss << error_string << " (" << static_cast<unsigned long>( err.encodedError() ) << ')';
55 return ss.str();
56}
57