Blame lang/cpp/src/exception.cpp

Packit d7e8d0
/*
Packit d7e8d0
  exception.cpp - exception wrapping a gpgme error
Packit d7e8d0
  Copyright (C) 2007 Klarälvdalens Datakonsult AB
Packit d7e8d0
  2016 Bundesamt für Sicherheit in der Informationstechnik
Packit d7e8d0
  Software engineering by Intevation GmbH
Packit d7e8d0
Packit d7e8d0
  This file is part of GPGME++.
Packit d7e8d0
Packit d7e8d0
  GPGME++ is free software; you can redistribute it and/or
Packit d7e8d0
  modify it under the terms of the GNU Library General Public
Packit d7e8d0
  License as published by the Free Software Foundation; either
Packit d7e8d0
  version 2 of the License, or (at your option) any later version.
Packit d7e8d0
Packit d7e8d0
  GPGME++ is distributed in the hope that it will be useful,
Packit d7e8d0
  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit d7e8d0
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit d7e8d0
  GNU Library General Public License for more details.
Packit d7e8d0
Packit d7e8d0
  You should have received a copy of the GNU Library General Public License
Packit d7e8d0
  along with GPGME++; see the file COPYING.LIB.  If not, write to the
Packit d7e8d0
  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Packit d7e8d0
  Boston, MA 02110-1301, USA.
Packit d7e8d0
*/
Packit d7e8d0
Packit d7e8d0
// -*- c++ -*-
Packit d7e8d0
#ifdef HAVE_CONFIG_H
Packit d7e8d0
 #include "config.h"
Packit d7e8d0
#endif
Packit d7e8d0
Packit d7e8d0
#include "exception.h"
Packit d7e8d0
Packit d7e8d0
#include <gpgme.h>
Packit d7e8d0
Packit d7e8d0
#include <sstream>
Packit d7e8d0
Packit d7e8d0
using namespace GpgME;
Packit d7e8d0
using namespace std; // only safe b/c it's so small a file!
Packit d7e8d0
Packit d7e8d0
Exception::~Exception() throw() {}
Packit d7e8d0
Packit d7e8d0
// static
Packit d7e8d0
string Exception::make_message(const Error &err, const string &msg)
Packit d7e8d0
{
Packit d7e8d0
    return make_message(err, msg, NoOptions);
Packit d7e8d0
}
Packit d7e8d0
Packit d7e8d0
// static
Packit d7e8d0
string Exception::make_message(const Error &err, const string &msg, Options opt)
Packit d7e8d0
{
Packit d7e8d0
    if (opt & MessageOnly) {
Packit d7e8d0
        return msg;
Packit d7e8d0
    }
Packit d7e8d0
    char error_string[128];
Packit d7e8d0
    error_string[0] = '\0';
Packit d7e8d0
    gpgme_strerror_r(err.encodedError(), error_string, sizeof error_string);
Packit d7e8d0
    error_string[sizeof error_string - 1] = '\0';
Packit d7e8d0
    stringstream ss;
Packit d7e8d0
    ss << gpgme_strsource(err.encodedError()) << ": ";
Packit d7e8d0
    if (!msg.empty()) {
Packit d7e8d0
        ss << msg << ": ";
Packit d7e8d0
    }
Packit d7e8d0
    ss << error_string << " (" << static_cast<unsigned long>(err.encodedError()) << ')';
Packit d7e8d0
    return ss.str();
Packit d7e8d0
}