folly::TryException inherits from std::logic_error, like std::bad_optional_access...
authorEric Niebler <eniebler@fb.com>
Thu, 29 Dec 2016 19:51:18 +0000 (11:51 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 29 Dec 2016 20:03:05 +0000 (12:03 -0800)
commit06649f434861ba1a287df67ce28486879a5cddc6
tree0bd6150afeba60657335158b1011d80d6c311c52
parent42ba1a2241675cac61c0b61214d2a895ef0c2a3e
folly::TryException inherits from std::logic_error, like std::bad_optional_access; becomes no-throw copyable

Summary:
folly::TryException was inheriting from std::exception and managing its own message in a std::string data member.
That is suboptimal for the following reasons:

1) The analagous std:: type, std::bad_optional_access, inherits from std::logic_error. According to the Principle of Least
   Astonishment, folly::TryException should follow suit.
2) std::logic_error has a nothrow copy constructor. (This is typically implemented with a ref-counted string.)
   std::string does not. By explicitly managing its own message, folly::TryException picks up a throwing copy
   constructor. Exception classes should try to be nothrow copyable.
3) With most stdlib implementations, std::string is larger by a lot than the std:: exceptions. By changing
   folly::TryException as suggested, its size drops from 40 bytes to 16 on clang and gcc >=5.0.

Reviewed By: yfeldblum

Differential Revision: D4368760

fbshipit-source-id: 327f78f428419ccf9c7af3e0f57cc478d147fb37
folly/Try.h