From 266ccb57e47f51a43dd01e19abcf7ec568b07d17 Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Tue, 1 Dec 2015 23:36:55 -0800 Subject: [PATCH] Recommend a different exception_handler idiom MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Summary: This is a //tiny// documentation change. I noticed that there are lots of places in the codebase where people follow this recommended usage of `with_exception` in an if–else chain, (e.g., https://fburl.com/181606454). IMHO, a short-circuiting `||` operator is easier to read and write. Reviewed By: yfeldblum Differential Revision: D2687840 fb-gh-sync-id: 6354555aeba81dcfe7adf17e7e573de0b1206b37 --- folly/ExceptionWrapper.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/folly/ExceptionWrapper.h b/folly/ExceptionWrapper.h index 7a5610b7..7909fb05 100644 --- a/folly/ExceptionWrapper.h +++ b/folly/ExceptionWrapper.h @@ -88,16 +88,15 @@ namespace folly { * * // Thread2: Exceptions are bad! * void processResult() { - * auto ep = globalExceptionWrapper.get(); - * if (!ep.with_exception([&]( - * FacePlantException& faceplant) { - * LOG(ERROR) << "FACEPLANT"; - * })) { - * ep.with_exception([&]( - * FailWhaleException& failwhale) { + * globalExceptionWrapper.with_exception( + * [&](FacePlantException& faceplant) { + * LOG(ERROR) << "FACEPLANT"; + * }) || + * globalExceptionWrapper.with_exception( + * [&](FailWhaleException& failwhale) { * LOG(ERROR) << "FAILWHALE!"; - * }); - * } + * }) || + * LOG(FATAL) << "Unrecognized exception"; * } * */ -- 2.34.1