Coverage Report

Created: 2022-08-24 06:38

/src/solidity/libsolutil/Exceptions.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
  This file is part of solidity.
3
4
  solidity is free software: you can redistribute it and/or modify
5
  it under the terms of the GNU General Public License as published by
6
  the Free Software Foundation, either version 3 of the License, or
7
  (at your option) any later version.
8
9
  solidity is distributed in the hope that it will be useful,
10
  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
  GNU General Public License for more details.
13
14
  You should have received a copy of the GNU General Public License
15
  along with solidity.  If not, see <http://www.gnu.org/licenses/>.
16
*/
17
// SPDX-License-Identifier: GPL-3.0
18
19
#include <libsolutil/Exceptions.h>
20
21
using namespace std;
22
using namespace solidity::util;
23
24
char const* Exception::what() const noexcept
25
0
{
26
  // Return the comment if available.
27
0
  if (string const* cmt = comment())
28
0
    return cmt->data();
29
30
  // Fallback to base what().
31
  // Boost accepts nullptr, but the C++ standard doesn't
32
  // and crashes on some platforms.
33
0
  return std::exception::what();
34
0
}
35
36
string Exception::lineInfo() const
37
0
{
38
0
  char const* const* file = boost::get_error_info<boost::throw_file>(*this);
39
0
  int const* line = boost::get_error_info<boost::throw_line>(*this);
40
0
  string ret;
41
0
  if (file)
42
0
    ret += *file;
43
0
  ret += ':';
44
0
  if (line)
45
0
    ret += to_string(*line);
46
0
  return ret;
47
0
}
48
49
string const* Exception::comment() const noexcept
50
0
{
51
0
  return boost::get_error_info<errinfo_comment>(*this);
52
0
}