From: Chad Parry Date: Mon, 23 Nov 2015 20:00:54 +0000 (-0800) Subject: Simplify an exception handler X-Git-Tag: deprecate-dynamic-initializer~238 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=6bafdff6699540b1e65a665b6d924a35ccafcd9c;p=folly.git Simplify an exception handler Summary: It looks like there is no reason to catch a `std::exception` and then `dynamic_cast` to a derived exception. We can just catch the derived exception directly. whatcouldgowrong4 Reviewed By: yfeldblum Differential Revision: D2677284 fb-gh-sync-id: 0149e4d4aecc96257376d410f592620205441f66 --- diff --git a/folly/ExceptionWrapper.h b/folly/ExceptionWrapper.h index 98ff9cb5..bc8c9758 100644 --- a/folly/ExceptionWrapper.h +++ b/folly/ExceptionWrapper.h @@ -214,8 +214,8 @@ class exception_wrapper { } else if (eptr_) { try { std::rethrow_exception(eptr_); - } catch (std::exception& e) { - return dynamic_cast(&e); + } catch (typename std::decay::type&) { + return true; } catch (...) { // fall through } @@ -323,11 +323,9 @@ private: } else if (that->eptr_) { try { std::rethrow_exception(that->eptr_); - } catch (std::exception& e) { - if (auto ex = dynamic_cast(&e)) { - f(*ex); - return true; - } + } catch (Ex& e) { + f(e); + return true; } catch (...) { // fall through }