summaryrefslogtreecommitdiff
path: root/indra/test/catch_and_store_what_in.h
diff options
context:
space:
mode:
authorAndreyL ProductEngine <alihatskiy@productengine.com>2019-11-27 22:58:52 +0200
committerAndreyL ProductEngine <alihatskiy@productengine.com>2019-11-27 22:58:52 +0200
commitbc496f5f17a446af27b47cbe227e7e85089bab8d (patch)
treeb7c90fee48d1f48e21c5f62fe84abaca16f8bb81 /indra/test/catch_and_store_what_in.h
parent91c311dd7beb8d723a00efac8e61019eeb8af17b (diff)
parentf89c9e9b20a13acd8f6af76699259cab4c74d5db (diff)
Downstream merge from lindenlab/viewer-lynx
Diffstat (limited to 'indra/test/catch_and_store_what_in.h')
-rw-r--r--indra/test/catch_and_store_what_in.h26
1 files changed, 25 insertions, 1 deletions
diff --git a/indra/test/catch_and_store_what_in.h b/indra/test/catch_and_store_what_in.h
index 59f8cc0085..5beba06024 100644
--- a/indra/test/catch_and_store_what_in.h
+++ b/indra/test/catch_and_store_what_in.h
@@ -2,7 +2,7 @@
* @file catch_and_store_what_in.h
* @author Nat Goodspeed
* @date 2012-02-15
- * @brief CATCH_AND_STORE_WHAT_IN() macro
+ * @brief catch_what() template function, CATCH_AND_STORE_WHAT_IN() macro
*
* $LicenseInfo:firstyear=2012&license=viewerlgpl$
* Copyright (c) 2012, Linden Research, Inc.
@@ -13,6 +13,30 @@
#define LL_CATCH_AND_STORE_WHAT_IN_H
/**
+ * In the brave new world of lambdas, we can use a nicer C++ idiom for testing
+ * exceptions than CATCH_AND_STORE_WHAT_IN() below, e.g.:
+ *
+ * @code
+ * std::string threw = catch_what<std::runtime_error>(
+ * [](){ throw std::runtime_error("badness"); });
+ * ensure_equals(threw, "badness");
+ * @endcode
+ */
+template <typename EXCEPTION, typename FUNC>
+std::string catch_what(FUNC func)
+{
+ try
+ {
+ func();
+ return {};
+ }
+ catch (const EXCEPTION& err)
+ {
+ return err.what();
+ }
+}
+
+/**
* Idiom useful for test programs: catch an expected exception, store its
* what() string in a specified std::string variable. From there the caller
* can do things like: