Define solThrow() macro to make throwing simple errors less verbose

This commit is contained in:
Kamil Śliwak 2021-10-08 14:44:43 +02:00
parent cd22574072
commit ee1455ce95
2 changed files with 16 additions and 8 deletions

View File

@ -61,14 +61,9 @@ inline std::string stringOrDefault(std::string _string, std::string _defaultStri
do \
{ \
if (!(_condition)) \
::boost::throw_exception( \
_exceptionType() << \
::solidity::util::errinfo_comment( \
::solidity::util::assertions::stringOrDefault(_description, _defaultDescription) \
) << \
::boost::throw_function(ETH_FUNC) << \
::boost::throw_file(__FILE__) << \
::boost::throw_line(__LINE__) \
solThrow( \
_exceptionType, \
::solidity::util::assertions::stringOrDefault(_description, _defaultDescription) \
); \
} \
while (false)

View File

@ -43,6 +43,19 @@ struct Exception: virtual std::exception, virtual boost::exception
private:
};
/// Throws an exception with a given description and extra information about the location the
/// exception was thrown from.
/// @param _exceptionType The type of the exception to throw (not an instance).
/// @param _description The message that describes the error.
#define solThrow(_exceptionType, _description) \
::boost::throw_exception( \
_exceptionType() << \
::solidity::util::errinfo_comment(_description) << \
::boost::throw_function(ETH_FUNC) << \
::boost::throw_file(__FILE__) << \
::boost::throw_line(__LINE__) \
)
#define DEV_SIMPLE_EXCEPTION(X) struct X: virtual ::solidity::util::Exception { const char* what() const noexcept override { return #X; } }
DEV_SIMPLE_EXCEPTION(InvalidAddress);