tests: in LimitedIo, use std::exception_ptr to avoid slicing

Change-Id: I459792cf80ee189842ada84c3a514134bcd79a29
Refs: #3327
diff --git a/tests/limited-io.hpp b/tests/limited-io.hpp
index 437335c..4891b8a 100644
--- a/tests/limited-io.hpp
+++ b/tests/limited-io.hpp
@@ -27,9 +27,10 @@
 #define NFD_TESTS_LIMITED_IO_HPP
 
 #include "test-common.hpp"
-#include "core/global-io.hpp"
 #include "core/scheduler.hpp"
 
+#include <exception>
+
 namespace nfd {
 namespace tests {
 
@@ -38,15 +39,13 @@
 class LimitedIo : noncopyable
 {
 public:
-  LimitedIo();
-
   /** \brief construct with UnitTestTimeFixture
    */
-  LimitedIo(UnitTestTimeFixture* uttf);
+  explicit
+  LimitedIo(UnitTestTimeFixture* uttf = nullptr);
 
   /// indicates why .run returns
-  enum StopReason
-  {
+  enum StopReason {
     /// g_io.run() returns normally because there's no work to do
     NO_WORK,
     /// .afterOp() has been invoked nOpsLimit times
@@ -71,9 +70,6 @@
   void
   afterOp();
 
-  const std::exception&
-  getLastException() const;
-
   /** \brief defer for specified duration
    *
    *  equivalent to .run(UNLIMITED_OPS, d)
@@ -84,6 +80,12 @@
     this->run(UNLIMITED_OPS, d);
   }
 
+  std::exception_ptr
+  getLastException() const
+  {
+    return m_lastException;
+  }
+
 private:
   /** \brief an exception to stop IO operation
    */
@@ -100,11 +102,11 @@
 
 private:
   UnitTestTimeFixture* m_uttf;
-  bool m_isRunning;
+  StopReason m_reason;
   int m_nOpsRemaining;
   scheduler::EventId m_timeout;
-  StopReason m_reason;
-  std::exception m_lastException;
+  std::exception_ptr m_lastException;
+  bool m_isRunning;
 };
 
 } // namespace tests