/src/solidity/libsolutil/Exceptions.cpp
Line | Count | Source |
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 | | #include <liblangutil/Exceptions.h> |
21 | | |
22 | | using namespace solidity::util; |
23 | | using namespace solidity::langutil; |
24 | | |
25 | | char const* Exception::what() const noexcept |
26 | 171 | { |
27 | | // Return the comment if available. |
28 | 171 | if (std::string const* cmt = comment()) |
29 | 171 | return cmt->data(); |
30 | | |
31 | | // Fallback to base what(). |
32 | | // Boost accepts nullptr, but the C++ standard doesn't |
33 | | // and crashes on some platforms. |
34 | 0 | return std::exception::what(); |
35 | 171 | } |
36 | | |
37 | | std::string Exception::lineInfo() const |
38 | 0 | { |
39 | 0 | char const* const* file = boost::get_error_info<boost::throw_file>(*this); |
40 | 0 | int const* line = boost::get_error_info<boost::throw_line>(*this); |
41 | 0 | std::string ret; |
42 | 0 | if (file) |
43 | 0 | ret += *file; |
44 | 0 | ret += ':'; |
45 | 0 | if (line) |
46 | 0 | ret += std::to_string(*line); |
47 | 0 | return ret; |
48 | 0 | } |
49 | | |
50 | | std::string const* Exception::comment() const noexcept |
51 | 2.58k | { |
52 | 2.58k | return boost::get_error_info<errinfo_comment>(*this); |
53 | 2.58k | } |
54 | | |
55 | | SourceLocation Exception::sourceLocation() const noexcept |
56 | 428 | { |
57 | 428 | if (SourceLocation const* sourceLocation = boost::get_error_info<errinfo_sourceLocation>(*this)) |
58 | 0 | return *sourceLocation; |
59 | | |
60 | 428 | return SourceLocation{}; |
61 | 428 | } |