Fix wrong exception handling 48/282448/4
authorChanggyu Choi <changyu.choi@samsung.com>
Tue, 4 Oct 2022 02:47:34 +0000 (11:47 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Tue, 4 Oct 2022 04:37:12 +0000 (13:37 +0900)
Change-Id: Ifd4f0104ad69dbcaddbdc31a75e84b676471716e
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
benchmark/server/main.cc
benchmark/tool/main.cc

index c4466cf..9be81a1 100644 (file)
@@ -29,14 +29,14 @@ namespace bs = rpc_port::BenchmarkStub::stub;
 class TestService : public bs::Benchmark::ServiceBase {
  public:
   class Factory : public bs::Benchmark::ServiceBase::Factory {
-     public:
-      virtual ~Factory() = default;
-
-      std::unique_ptr<bs::Benchmark::ServiceBase>
-          CreateService(std::string sender, std::string instance) {
-        return std::unique_ptr<bs::Benchmark::ServiceBase>(
-            new TestService(sender, instance));
-      }
+   public:
+    virtual ~Factory() = default;
+
+    std::unique_ptr<bs::Benchmark::ServiceBase>
+        CreateService(std::string sender, std::string instance) {
+      return std::unique_ptr<bs::Benchmark::ServiceBase>(
+          new TestService(sender, instance));
+    }
   };
 
   TestService(std::string sender, std::string instance) :
@@ -75,9 +75,10 @@ class MainLoop {
     try {
       stub_.Listen(std::shared_ptr<bs::Benchmark::ServiceBase::Factory>(
           new TestService::Factory()));
-    } catch (const std::exception& e) {
-      _E("stub listen is failed(%s)", e.what());
+    } catch (const bs::Exception&) {
+      _E("stub listen is failed");
     }
+
     g_main_loop_run(loop_);
   }
 
index 580eb69..8abe412 100644 (file)
@@ -65,8 +65,8 @@ class Tester {
   void Run(int argc, char** argv) {
     options_ = rpc_port::benchmark::Options::Parse(argc, argv);
     if (!options_) {
-      _E("options is nullptr");
-      exit(1);
+      std::cerr << "options is unllptr" << std::endl;
+      return;
     }
 
     ExecuteServer();
@@ -75,28 +75,36 @@ class Tester {
     try {
       proxy_->Connect(true);
     } catch (const bp::Exception& e) {
-      _E("Connect() failed");
-      exit(1);
+      std::cerr << "Connect() failed" << std::endl;
+      return;
+    } catch (const std::exception& e) {
+      std::cerr << "Connect() failed. " << e.what() << std::endl;
+      return;
     }
 
     printf("%15s\t%15s\t%15s\t\t%15s\t\t%15s\n", "Iterations", "Data size",
         "Time", "Throughput", "Latency");
-    if (options_->IsAll()) {
-      DoTest(4000, 10);
-      DoTest(4000, 20);
-      DoTest(4000, 100);
-      DoTest(4000, 200);
-      DoTest(2000, 1000);
-      DoTest(2000, 2000);
-      DoTest(1000, 10000);
-      DoTest(1000, 20000);
-      DoTest(1000, 30000);
-      DoTest(1000, 40000);
-      DoTest(1000, 50000);
-      DoTest(1000, 60000);
-      DoTest(500, 100000);
-    } else {
-      DoTest(options_->GetIters(), options_->GetSize());
+
+    try {
+      if (options_->IsAll()) {
+        DoTest(4000, 10);
+        DoTest(4000, 20);
+        DoTest(4000, 100);
+        DoTest(4000, 200);
+        DoTest(2000, 1000);
+        DoTest(2000, 2000);
+        DoTest(1000, 10000);
+        DoTest(1000, 20000);
+        DoTest(1000, 30000);
+        DoTest(1000, 40000);
+        DoTest(1000, 50000);
+        DoTest(1000, 60000);
+        DoTest(500, 100000);
+      } else {
+        DoTest(options_->GetIters(), options_->GetSize());
+      }
+    } catch (const bp::Exception& e) {
+      std::cerr << "test failed" << std::endl;
     }
   }
 
@@ -134,7 +142,8 @@ class Tester {
   }
 
   void EndTime(int iters, int size) {
-    std::chrono::duration<double> sec = std::chrono::system_clock::now() - start_;
+    std::chrono::duration<double> sec =
+        std::chrono::system_clock::now() - start_;
     double t = size * iters * 8 / sec.count() / 1024 / 1024;
     double l = sec.count() * 1000 / iters;
 
@@ -175,11 +184,6 @@ class Tester {
 
 int main(int argc, char** argv) {
   Tester tester;
-  try {
-    tester.Run(argc, argv);
-  } catch (const std::exception& e) {
-    std::cerr << "Exception occurred!!!" << e.what() << std::endl;
-  }
-
+  tester.Run(argc, argv);
   return 0;
 }