Ethereum  PoC-8
The C++ Implementation of Ethereum
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 "FixedHash.h"
25 #include <boost/exception/diagnostic_information.hpp>
26 #include <boost/exception/errinfo_api_function.hpp>
27 #include <boost/exception/exception.hpp>
28 #include <boost/exception/info.hpp>
29 #include <boost/exception/info_tuple.hpp>
30 #include <boost/throw_exception.hpp>
31 #include <boost/tuple/tuple.hpp>
32 #include <exception>
33 #include <string>
34 
35 namespace dev
36 {
38 struct Exception : virtual std::exception, virtual boost::exception
39 {
40  const char* what() const noexcept override { return boost::diagnostic_information_what(*this); }
41 };
42 
43 #define DEV_SIMPLE_EXCEPTION(X) \
44  struct X : virtual Exception \
45  { \
46  }
47 
49 struct RLPException : virtual Exception
50 {
51 };
52 #define DEV_SIMPLE_EXCEPTION_RLP(X) \
53  struct X : virtual RLPException \
54  { \
55  }
56 
59 DEV_SIMPLE_EXCEPTION_RLP(OversizeRLP);
60 DEV_SIMPLE_EXCEPTION_RLP(UndersizeRLP);
61 
62 DEV_SIMPLE_EXCEPTION(BadHexCharacter);
63 DEV_SIMPLE_EXCEPTION(NoNetworking);
64 DEV_SIMPLE_EXCEPTION(NoUPnPDevice);
65 DEV_SIMPLE_EXCEPTION(RootNotFound);
66 DEV_SIMPLE_EXCEPTION(BadRoot);
67 DEV_SIMPLE_EXCEPTION(FileError);
68 DEV_SIMPLE_EXCEPTION(Overflow);
69 DEV_SIMPLE_EXCEPTION(FailedInvariant);
70 DEV_SIMPLE_EXCEPTION(ValueTooLarge);
71 DEV_SIMPLE_EXCEPTION(UnknownField);
72 DEV_SIMPLE_EXCEPTION(MissingField);
73 DEV_SIMPLE_EXCEPTION(WrongFieldType);
74 DEV_SIMPLE_EXCEPTION(InterfaceNotSupported);
75 DEV_SIMPLE_EXCEPTION(ExternalFunctionFailure);
76 DEV_SIMPLE_EXCEPTION(WaitTimeout);
77 
78 // error information to be added to exceptions
79 using errinfo_invalidSymbol = boost::error_info<struct tag_invalidSymbol, char>;
80 using errinfo_wrongAddress = boost::error_info<struct tag_address, std::string>;
81 using errinfo_comment = boost::error_info<struct tag_comment, std::string>;
82 using errinfo_required = boost::error_info<struct tag_required, bigint>;
83 using errinfo_got = boost::error_info<struct tag_got, bigint>;
84 using errinfo_min = boost::error_info<struct tag_min, bigint>;
85 using errinfo_max = boost::error_info<struct tag_max, bigint>;
86 using RequirementError = boost::tuple<errinfo_required, errinfo_got>;
87 using RequirementErrorComment = boost::tuple<errinfo_required, errinfo_got, errinfo_comment>;
88 using errinfo_hash256 = boost::error_info<struct tag_hash, h256>;
89 using errinfo_required_h256 = boost::error_info<struct tag_required_h256, h256>;
90 using errinfo_got_h256 = boost::error_info<struct tag_get_h256, h256>;
91 using Hash256RequirementError = boost::tuple<errinfo_required_h256, errinfo_got_h256>;
92 using errinfo_extraData = boost::error_info<struct tag_extraData, bytes>;
93 using errinfo_externalFunction = boost::errinfo_api_function;
94 using errinfo_interface = boost::error_info<struct tag_interface, std::string>;
95 using errinfo_path = boost::error_info<struct tag_path, std::string>;
96 using errinfo_nodeID = boost::error_info<struct tag_nodeID, h512>;
97 }
Definition: Address.cpp:20
boost::tuple< errinfo_required_h256, errinfo_got_h256 > Hash256RequirementError
Definition: Exceptions.h:91
boost::error_info< struct tag_path, std::string > errinfo_path
Definition: Exceptions.h:95
boost::error_info< struct tag_min, bigint > errinfo_min
Definition: Exceptions.h:84
boost::error_info< struct tag_max, bigint > errinfo_max
Definition: Exceptions.h:85
boost::error_info< struct tag_address, std::string > errinfo_wrongAddress
Definition: Exceptions.h:80
boost::error_info< struct tag_invalidSymbol, char > errinfo_invalidSymbol
Definition: Exceptions.h:79
boost::error_info< struct tag_hash, h256 > errinfo_hash256
Definition: Exceptions.h:88
Base class for all exceptions.
Definition: Exceptions.h:38
boost::error_info< struct tag_got, bigint > errinfo_got
Definition: Exceptions.h:83
boost::error_info< struct tag_required_h256, h256 > errinfo_required_h256
Definition: Exceptions.h:89
DEV_SIMPLE_EXCEPTION_RLP(BadCast)
boost::error_info< struct tag_extraData, bytes > errinfo_extraData
Definition: Exceptions.h:92
boost::errinfo_api_function errinfo_externalFunction
Definition: Exceptions.h:93
boost::error_info< struct tag_nodeID, h512 > errinfo_nodeID
Definition: Exceptions.h:96
boost::tuple< errinfo_required, errinfo_got, errinfo_comment > RequirementErrorComment
Definition: Exceptions.h:87
boost::error_info< struct tag_required, bigint > errinfo_required
Definition: Exceptions.h:82
const char * what() const noexcept override
Definition: Exceptions.h:40
DEV_SIMPLE_EXCEPTION(BadHexCharacter)
Base class for all RLP exceptions.
Definition: Exceptions.h:49
boost::error_info< struct tag_comment, std::string > errinfo_comment
Definition: Assertions.h:69
boost::error_info< struct tag_get_h256, h256 > errinfo_got_h256
Definition: Exceptions.h:90
boost::tuple< errinfo_required, errinfo_got > RequirementError
Definition: Exceptions.h:86
boost::error_info< struct tag_interface, std::string > errinfo_interface
Definition: Exceptions.h:94