Skip to content

Commit ee1455c

Browse files
committed
Define solThrow() macro to make throwing simple errors less verbose
1 parent cd22574 commit ee1455c

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

libsolutil/Assertions.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,9 @@ inline std::string stringOrDefault(std::string _string, std::string _defaultStri
6161
do \
6262
{ \
6363
if (!(_condition)) \
64-
::boost::throw_exception( \
65-
_exceptionType() << \
66-
::solidity::util::errinfo_comment( \
67-
::solidity::util::assertions::stringOrDefault(_description, _defaultDescription) \
68-
) << \
69-
::boost::throw_function(ETH_FUNC) << \
70-
::boost::throw_file(__FILE__) << \
71-
::boost::throw_line(__LINE__) \
64+
solThrow( \
65+
_exceptionType, \
66+
::solidity::util::assertions::stringOrDefault(_description, _defaultDescription) \
7267
); \
7368
} \
7469
while (false)

libsolutil/Exceptions.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ struct Exception: virtual std::exception, virtual boost::exception
4343
private:
4444
};
4545

46+
/// Throws an exception with a given description and extra information about the location the
47+
/// exception was thrown from.
48+
/// @param _exceptionType The type of the exception to throw (not an instance).
49+
/// @param _description The message that describes the error.
50+
#define solThrow(_exceptionType, _description) \
51+
::boost::throw_exception( \
52+
_exceptionType() << \
53+
::solidity::util::errinfo_comment(_description) << \
54+
::boost::throw_function(ETH_FUNC) << \
55+
::boost::throw_file(__FILE__) << \
56+
::boost::throw_line(__LINE__) \
57+
)
58+
4659
#define DEV_SIMPLE_EXCEPTION(X) struct X: virtual ::solidity::util::Exception { const char* what() const noexcept override { return #X; } }
4760

4861
DEV_SIMPLE_EXCEPTION(InvalidAddress);

0 commit comments

Comments
 (0)