Skip to content

Commit

Permalink
Add exception handling to cpp examples
Browse files Browse the repository at this point in the history
Getting rid of uncaught exception issue pointed out by Coverty scan
  • Loading branch information
dalg24 committed Dec 15, 2016
1 parent c530c3d commit e7c9e78
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions cpp/example/scaling.cc
Expand Up @@ -8,10 +8,8 @@
#include <boost/mpi/timer.hpp>
#include <iostream>

int main(int argc, char *argv[])
void run_example(boost::mpi::communicator &comm)
{
boost::mpi::environment env(argc, argv);
boost::mpi::communicator comm;
boost::mpi::timer timer;
if (comm.rank() == 0)
std::cout << "Number of processors: " << comm.size() << std::endl;
Expand Down Expand Up @@ -49,6 +47,41 @@ int main(int argc, char *argv[])
cap::SuperCapacitorInspector<3> supercap_inspector;
supercap_inspector.inspect(device.get());
}
}

int main(int argc, char *argv[])
{
try
{
boost::mpi::environment env(argc, argv);
boost::mpi::communicator world;
run_example(world);
}
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;
}

return 0;
}

0 comments on commit e7c9e78

Please sign in to comment.