exceptionStr(exception_wrapper)
authorJames Sedgwick <jsedgwick@fb.com>
Mon, 16 Mar 2015 16:02:24 +0000 (09:02 -0700)
committerAndre Azevedo <aap@fb.com>
Wed, 18 Mar 2015 03:18:46 +0000 (20:18 -0700)
Summary: for consistency with exception and exception_ptr functions provided in String.h

Test Plan: unit

Reviewed By: vloh@fb.com

Subscribers: trunkagent, folly-diffs@, yfeldblum

FB internal diff: D1905087

Tasks: 5961362

Signature: t1:1905087:1426101740:670ceab5140250bbecdd1247025d3d70b7774690

folly/ExceptionWrapper.h
folly/test/ExceptionWrapperTest.cpp

index 8284ec1fa538ecc20be819bdf7b58bfb818b6987..3f9f9688f754f8ce47a389a6308fca1d5a9b532e 100644 (file)
@@ -342,6 +342,11 @@ exception_wrapper make_exception_wrapper(Args&&... args) {
   return ew;
 }
 
+// For consistency with exceptionStr() functions in String.h
+inline fbstring exceptionStr(const exception_wrapper& ew) {
+  return ew.what();
+}
+
 /*
  * try_and_catch is a simple replacement for try {} catch(){} that allows you to
  * specify which derived exceptions you would like to catch and store in an
index a2c62bd453af6a80b4ddbf64b3b19fab53ae6faa..a12445adb514fab2e6c9cba6a8b3ab35cc592460 100644 (file)
@@ -221,3 +221,9 @@ TEST(ExceptionWrapper, non_std_exception_test) {
     EXPECT_EQ(i, expected);
   }
 }
+
+
+TEST(ExceptionWrapper, exceptionStr) {
+  auto ew = make_exception_wrapper<std::runtime_error>("argh");
+  EXPECT_EQ("std::runtime_error: argh", exceptionStr(ew));
+}