From 1dff5eaf643d6fda3d04345d6a385394e11e7d3c Mon Sep 17 00:00:00 2001 From: Patrick Brosi Date: Mon, 11 Feb 2019 17:55:05 +0100 Subject: [PATCH] catch polymorphic exceptions by const reference --- src/pfaedle/PfaedleMain.cpp | 12 ++++++------ src/util/http/Server.cpp | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/pfaedle/PfaedleMain.cpp b/src/pfaedle/PfaedleMain.cpp index 0f93134..80a8ec4 100644 --- a/src/pfaedle/PfaedleMain.cpp +++ b/src/pfaedle/PfaedleMain.cpp @@ -80,7 +80,7 @@ int main(int argc, char** argv) { try { motCfgReader.parse(cfgPaths); - } catch (configparser::ParseExc ex) { + } catch (const configparser::ParseExc& ex) { LOG(ERROR) << "Could not parse MOT configurations, reason was:"; std::cerr << ex.what() << std::endl; exit(static_cast(RetCode::MOT_CFG_PARSE_ERR)); @@ -108,7 +108,7 @@ int main(int argc, char** argv) { // read the shapes and store them in memory p.parseShapes(&evalFeed, cfg.feedPaths[0]); } - } catch (ad::cppgtfs::ParserException ex) { + } catch (const ad::cppgtfs::ParserException& ex) { LOG(ERROR) << "Could not parse input GTFS feed, reason was:"; std::cerr << ex.what() << std::endl; exit(static_cast(RetCode::GTFS_PARSE_ERR)); @@ -121,7 +121,7 @@ int main(int argc, char** argv) { ad::cppgtfs::Parser p; try { p.parse(>fs[i], cfg.feedPaths[i]); - } catch (ad::cppgtfs::ParserException ex) { + } catch (const ad::cppgtfs::ParserException& ex) { LOG(ERROR) << "Could not parse input GTFS feed, reason was:"; std::cerr << ex.what() << std::endl; exit(static_cast(RetCode::GTFS_PARSE_ERR)); @@ -167,7 +167,7 @@ int main(int argc, char** argv) { } try { osmBuilder.filterWrite(cfg.osmPath, cfg.writeOsm, opts, box); - } catch (xml::XmlFileException ex) { + } catch (const xml::XmlFileException& ex) { LOG(ERROR) << "Could not parse OSM data, reason was:"; std::cerr << ex.what() << std::endl; exit(static_cast(RetCode::OSM_PARSE_ERR)); @@ -276,7 +276,7 @@ int main(int argc, char** argv) { out.print(ng, fstr); fstr.close(); } - } catch (xml::XmlFileException ex) { + } catch (const xml::XmlFileException& ex) { LOG(ERROR) << "Could not parse OSM data, reason was:"; std::cerr << ex.what() << std::endl; exit(static_cast(RetCode::OSM_PARSE_ERR)); @@ -291,7 +291,7 @@ int main(int argc, char** argv) { LOG(INFO) << "Writing output GTFS to " << cfg.outputPath << " ..."; pfaedle::gtfs::Writer w; w.write(>fs[0], cfg.outputPath); - } catch (ad::cppgtfs::WriterException ex) { + } catch (const ad::cppgtfs::WriterException& ex) { LOG(ERROR) << "Could not write final GTFS feed, reason was:"; std::cerr << ex.what() << std::endl; exit(static_cast(RetCode::GTFS_WRITE_ERR)); diff --git a/src/util/http/Server.cpp b/src/util/http/Server.cpp index dacee83..fa20a97 100644 --- a/src/util/http/Server.cpp +++ b/src/util/http/Server.cpp @@ -105,7 +105,7 @@ void HttpServer::handle() { Req req = getReq(connection); answ = _handler->handle(req, connection); answ.gzip = gzipSupport(req); - } catch (HttpErr err) { + } catch (const HttpErr& err) { answ = Answer(err.what(), err.what()); } catch (...) { // catch everything to make sure the server continues running