Coverage Report

Created: 2022-08-24 06:40

/src/solidity/libsolutil/Exceptions.h
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
#pragma once
20
21
#include <boost/exception/exception.hpp>
22
#include <boost/exception/info.hpp>
23
#include <boost/exception/info_tuple.hpp>
24
#include <boost/exception/diagnostic_information.hpp>
25
26
#include <exception>
27
#include <string>
28
29
namespace solidity::util
30
{
31
32
/// Base class for all exceptions.
33
struct Exception: virtual std::exception, virtual boost::exception
34
{
35
  char const* what() const noexcept override;
36
37
  /// @returns "FileName:LineNumber" referring to the point where the exception was thrown.
38
  std::string lineInfo() const;
39
40
  /// @returns the errinfo_comment of this exception.
41
  std::string const* comment() const noexcept;
42
};
43
44
/// Throws an exception with a given description and extra information about the location the
45
/// exception was thrown from.
46
/// @param _exceptionType The type of the exception to throw (not an instance).
47
/// @param _description The message that describes the error.
48
#define solThrow(_exceptionType, _description) \
49
0
  ::boost::throw_exception( \
50
0
    _exceptionType() << \
51
0
    ::solidity::util::errinfo_comment((_description)) << \
52
0
    ::boost::throw_function(ETH_FUNC) << \
53
0
    ::boost::throw_file(__FILE__) << \
54
0
    ::boost::throw_line(__LINE__) \
55
0
  )
56
57
/// Defines an exception type that's meant to signal a specific condition and be caught rather than
58
/// unwind the stack all the way to the top-level exception handler and interrupt the program.
59
/// As such it does not carry a message - the code catching it is expected to handle it without
60
/// letting it escape.
61
0
#define DEV_SIMPLE_EXCEPTION(X) struct X: virtual ::solidity::util::Exception { const char* what() const noexcept override { return #X; } }
Unexecuted instantiation: solidity::util::InvalidAddress::what() const
Unexecuted instantiation: solidity::util::BadHexCharacter::what() const
Unexecuted instantiation: solidity::util::BadHexCase::what() const
Unexecuted instantiation: solidity::util::FileNotFound::what() const
Unexecuted instantiation: solidity::util::NotAFile::what() const
Unexecuted instantiation: solidity::util::DataTooLong::what() const
Unexecuted instantiation: solidity::util::StringTooLong::what() const
Unexecuted instantiation: solidity::evmasm::InvalidDeposit::what() const
Unexecuted instantiation: solidity::evmasm::InvalidOpcode::what() const
Unexecuted instantiation: solidity::smtutil::SolverError::what() const
62
63
DEV_SIMPLE_EXCEPTION(InvalidAddress);
64
DEV_SIMPLE_EXCEPTION(BadHexCharacter);
65
DEV_SIMPLE_EXCEPTION(BadHexCase);
66
DEV_SIMPLE_EXCEPTION(FileNotFound);
67
DEV_SIMPLE_EXCEPTION(NotAFile);
68
DEV_SIMPLE_EXCEPTION(DataTooLong);
69
DEV_SIMPLE_EXCEPTION(StringTooLong);
70
71
// error information to be added to exceptions
72
using errinfo_comment = boost::error_info<struct tag_comment, std::string>;
73
74
}