Recommend a different exception_handler idiom
authorChad Parry <cparry@fb.com>
Wed, 2 Dec 2015 07:36:55 +0000 (23:36 -0800)
committerfacebook-github-bot-1 <folly-bot@fb.com>
Wed, 2 Dec 2015 08:20:21 +0000 (00:20 -0800)
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

index 7a5610b73bd4d6de1bdc58e012c446c139425b20..7909fb053c56aa4b5678e26767cc2242ddf33e89 100644 (file)
@@ -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";
  * }
  *
  */