Saner test exception in ExceptionWrapperTest.cpp
authorYedidya Feldblum <yfeldblum@fb.com>
Fri, 9 Jun 2017 06:45:51 +0000 (23:45 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 9 Jun 2017 06:51:45 +0000 (23:51 -0700)
Summary:
[Folly] Saner test exception in `ExceptionWrapperTest.cpp`.

Make construction do the work and make `what()` free.

Reviewed By: andrewjcg

Differential Revision: D5216707

fbshipit-source-id: bfb4c2473a61ff7da7a3a01adc85facae30d6586

folly/test/ExceptionWrapperTest.cpp

index 07930ee0c2f098d28d6fd3edbfb7a09fec9dbedf..58a32a17b6d39b149b5518222a5aa4f0f17ce2c9 100644 (file)
@@ -29,17 +29,16 @@ class AbstractIntException : public std::exception {
 
 class IntException : public AbstractIntException {
  public:
-  explicit IntException(int i) : i_(i) {}
+  explicit IntException(int i) : i_(i), what_(to<std::string>("int == ", i_)) {}
 
   int getInt() const override { return i_; }
   const char* what() const noexcept override {
-    what_ = folly::to<std::string>("int == ", i_);
     return what_.c_str();
   }
 
  private:
   int i_;
-  mutable std::string what_;
+  std::string what_;
 };
 
 const static std::string kExceptionClassName =