From ae823da9fa80e7bb0db65b758073997707629895 Mon Sep 17 00:00:00 2001 From: James Sedgwick Date: Mon, 16 Mar 2015 09:02:24 -0700 Subject: [PATCH] exceptionStr(exception_wrapper) 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 | 5 +++++ folly/test/ExceptionWrapperTest.cpp | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/folly/ExceptionWrapper.h b/folly/ExceptionWrapper.h index 8284ec1f..3f9f9688 100644 --- a/folly/ExceptionWrapper.h +++ b/folly/ExceptionWrapper.h @@ -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 diff --git a/folly/test/ExceptionWrapperTest.cpp b/folly/test/ExceptionWrapperTest.cpp index a2c62bd4..a12445ad 100644 --- a/folly/test/ExceptionWrapperTest.cpp +++ b/folly/test/ExceptionWrapperTest.cpp @@ -221,3 +221,9 @@ TEST(ExceptionWrapper, non_std_exception_test) { EXPECT_EQ(i, expected); } } + + +TEST(ExceptionWrapper, exceptionStr) { + auto ew = make_exception_wrapper("argh"); + EXPECT_EQ("std::runtime_error: argh", exceptionStr(ew)); +} -- 2.34.1