blob: 217bf81eb0f0de83e5e54b579c6bff900ada7467 [file] [log] [blame]
weijia yuan3aa8d2b2018-03-06 15:35:57 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2018, Regents of the University of California.
4 *
5 * This file is part of NDN repo-ng (Next generation of NDN repository).
6 * See AUTHORS.md for complete list of repo-ng authors and contributors.
7 *
8 * repo-ng is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef REPO_EXTENDED_ERROR_MESSAGE_HPP
21#define REPO_EXTENDED_ERROR_MESSAGE_HPP
22
23#include <boost/exception/get_error_info.hpp>
24#include <sstream>
25
26namespace repo {
27
28template<typename E>
29std::string
30getExtendedErrorMessage(const E& exception)
31{
32 std::ostringstream errorMessage;
33 errorMessage << exception.what();
34
35 const char* const* file = boost::get_error_info<boost::throw_file>(exception);
36 const int* line = boost::get_error_info<boost::throw_line>(exception);
37 const char* const* func = boost::get_error_info<boost::throw_function>(exception);
38 if (file && line) {
39 errorMessage << " [from " << *file << ":" << *line;
40 if (func) {
41 errorMessage << " in " << *func;
42 }
43 errorMessage << "]";
44 }
45
46 return errorMessage.str();
47}
48
49} // namespace repo
50
51#endif // REPO_EXTENDED_ERROR_MESSAGE_HPP