Fabcoin Core  0.16.2
P2P Digital Currency
Exceptions.h
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum 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  cpp-ethereum 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 cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
22 #pragma once
23 
24 #include <exception>
25 #include <string>
26 #include <boost/exception/exception.hpp>
27 #include <boost/exception/info.hpp>
28 #include <boost/exception/info_tuple.hpp>
29 #include <boost/exception/diagnostic_information.hpp>
30 #include <boost/throw_exception.hpp>
31 #include <boost/tuple/tuple.hpp>
32 #include "CommonData.h"
33 #include "FixedHash.h"
34 
35 namespace dev
36 {
37 
39 struct Exception: virtual std::exception, virtual boost::exception
40 {
41  Exception(std::string _message = std::string()): m_message(std::move(_message)) {}
42  const char* what() const noexcept override { return m_message.empty() ? std::exception::what() : m_message.c_str(); }
43 
44 private:
45  std::string m_message;
46 };
47 
48 #define DEV_SIMPLE_EXCEPTION(X) struct X: virtual Exception { const char* what() const noexcept override { return #X; } }
49 
51 struct RLPException: virtual Exception { RLPException(std::string _message = std::string()): Exception(_message) {} };
52 #define DEV_SIMPLE_EXCEPTION_RLP(X) struct X: virtual RLPException { const char* what() const noexcept override { return #X; } }
53 
56 DEV_SIMPLE_EXCEPTION_RLP(OversizeRLP);
57 DEV_SIMPLE_EXCEPTION_RLP(UndersizeRLP);
58 
59 DEV_SIMPLE_EXCEPTION(BadHexCharacter);
60 DEV_SIMPLE_EXCEPTION(NoNetworking);
61 DEV_SIMPLE_EXCEPTION(NoUPnPDevice);
62 DEV_SIMPLE_EXCEPTION(RootNotFound);
63 struct BadRoot: virtual Exception { public: BadRoot(h256 const& _root): Exception("BadRoot " + _root.hex()), root(_root) {} h256 root; };
64 DEV_SIMPLE_EXCEPTION(FileError);
65 DEV_SIMPLE_EXCEPTION(Overflow);
66 DEV_SIMPLE_EXCEPTION(FailedInvariant);
67 DEV_SIMPLE_EXCEPTION(ValueTooLarge);
68 
69 struct InterfaceNotSupported: virtual Exception { public: InterfaceNotSupported(std::string _f): Exception("Interface " + _f + " not supported.") {} };
70 struct ExternalFunctionFailure: virtual Exception { public: ExternalFunctionFailure(std::string _f): Exception("Function " + _f + "() failed.") {} };
71 
72 // error information to be added to exceptions
73 using errinfo_invalidSymbol = boost::error_info<struct tag_invalidSymbol, char>;
74 using errinfo_wrongAddress = boost::error_info<struct tag_address, std::string>;
75 using errinfo_comment = boost::error_info<struct tag_comment, std::string>;
76 using errinfo_required = boost::error_info<struct tag_required, bigint>;
77 using errinfo_got = boost::error_info<struct tag_got, bigint>;
78 using errinfo_min = boost::error_info<struct tag_min, bigint>;
79 using errinfo_max = boost::error_info<struct tag_max, bigint>;
80 using RequirementError = boost::tuple<errinfo_required, errinfo_got>;
81 using errinfo_hash256 = boost::error_info<struct tag_hash, h256>;
82 using errinfo_required_h256 = boost::error_info<struct tag_required_h256, h256>;
83 using errinfo_got_h256 = boost::error_info<struct tag_get_h256, h256>;
84 using Hash256RequirementError = boost::tuple<errinfo_required_h256, errinfo_got_h256>;
85 using errinfo_extraData = boost::error_info<struct tag_extraData, bytes>;
86 
87 }
RLPException(std::string _message=std::string())
Definition: Exceptions.h:51
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
boost::tuple< errinfo_required_h256, errinfo_got_h256 > Hash256RequirementError
Definition: Exceptions.h:84
const char * what() const noexceptoverride
Definition: Exceptions.h:42
std::hash for asio::adress
Definition: Common.h:323
boost::error_info< struct tag_min, bigint > errinfo_min
Definition: Exceptions.h:78
boost::error_info< struct tag_max, bigint > errinfo_max
Definition: Exceptions.h:79
boost::error_info< struct tag_address, std::string > errinfo_wrongAddress
Definition: Exceptions.h:74
boost::error_info< struct tag_invalidSymbol, char > errinfo_invalidSymbol
Definition: Exceptions.h:73
boost::error_info< struct tag_hash, h256 > errinfo_hash256
Definition: Exceptions.h:81
Base class for all exceptions.
Definition: Exceptions.h:39
boost::error_info< struct tag_got, bigint > errinfo_got
Definition: Exceptions.h:77
boost::error_info< struct tag_required_h256, h256 > errinfo_required_h256
Definition: Exceptions.h:82
DEV_SIMPLE_EXCEPTION_RLP(BadCast)
InterfaceNotSupported(std::string _f)
Definition: Exceptions.h:69
std::string m_message
Definition: Exceptions.h:45
boost::error_info< struct tag_extraData, bytes > errinfo_extraData
Definition: Exceptions.h:85
boost::error_info< struct tag_required, bigint > errinfo_required
Definition: Exceptions.h:76
DEV_SIMPLE_EXCEPTION(BadHexCharacter)
Base class for all RLP exceptions.
Definition: Exceptions.h:51
boost::error_info< struct tag_comment, std::string > errinfo_comment
Definition: Assertions.h:78
boost::error_info< struct tag_get_h256, h256 > errinfo_got_h256
Definition: Exceptions.h:83
boost::tuple< errinfo_required, errinfo_got > RequirementError
Definition: Exceptions.h:80
Exception(std::string _message=std::string())
Definition: Exceptions.h:41
ExternalFunctionFailure(std::string _f)
Definition: Exceptions.h:70
std::string hex() const
Definition: FixedHash.h:130