From ee49cd4ba919e833eead786745a5c2b2abdf74a8 Mon Sep 17 00:00:00 2001 From: David Wells Date: Thu, 16 Mar 2017 20:38:43 -0400 Subject: [PATCH] Improve exception handling in two tutorials. These were caught by Coverity. --- examples/step-49/step-49.cc | 41 ++++++++++++++++++++++++++++++------- examples/step-50/step-50.cc | 1 - 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/examples/step-49/step-49.cc b/examples/step-49/step-49.cc index eeeb60cd37..b884ea8c6c 100644 --- a/examples/step-49/step-49.cc +++ b/examples/step-49/step-49.cc @@ -350,11 +350,38 @@ void grid_7() // subfunctions. int main () { - grid_1 (); - grid_2 (); - grid_3 (); - grid_4 (); - grid_5 (); - grid_6 (); - grid_7 (); + try + { + grid_1 (); + grid_2 (); + grid_3 (); + grid_4 (); + grid_5 (); + grid_6 (); + grid_7 (); + } + catch (std::exception &exc) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + } } diff --git a/examples/step-50/step-50.cc b/examples/step-50/step-50.cc index bff72b2018..69119e34ba 100644 --- a/examples/step-50/step-50.cc +++ b/examples/step-50/step-50.cc @@ -989,7 +989,6 @@ int main (int argc, char *argv[]) << "Aborting!" << std::endl << "----------------------------------------------------" << std::endl; - throw; } catch (...) { -- 2.39.5