catch polymorphic exceptions by const reference

This commit is contained in:
Patrick Brosi 2019-02-11 17:55:05 +01:00
parent d995f77b53
commit 1dff5eaf64
2 changed files with 7 additions and 7 deletions

View file

@ -80,7 +80,7 @@ int main(int argc, char** argv) {
try { try {
motCfgReader.parse(cfgPaths); motCfgReader.parse(cfgPaths);
} catch (configparser::ParseExc ex) { } catch (const configparser::ParseExc& ex) {
LOG(ERROR) << "Could not parse MOT configurations, reason was:"; LOG(ERROR) << "Could not parse MOT configurations, reason was:";
std::cerr << ex.what() << std::endl; std::cerr << ex.what() << std::endl;
exit(static_cast<int>(RetCode::MOT_CFG_PARSE_ERR)); exit(static_cast<int>(RetCode::MOT_CFG_PARSE_ERR));
@ -108,7 +108,7 @@ int main(int argc, char** argv) {
// read the shapes and store them in memory // read the shapes and store them in memory
p.parseShapes(&evalFeed, cfg.feedPaths[0]); 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:"; LOG(ERROR) << "Could not parse input GTFS feed, reason was:";
std::cerr << ex.what() << std::endl; std::cerr << ex.what() << std::endl;
exit(static_cast<int>(RetCode::GTFS_PARSE_ERR)); exit(static_cast<int>(RetCode::GTFS_PARSE_ERR));
@ -121,7 +121,7 @@ int main(int argc, char** argv) {
ad::cppgtfs::Parser p; ad::cppgtfs::Parser p;
try { try {
p.parse(&gtfs[i], cfg.feedPaths[i]); p.parse(&gtfs[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:"; LOG(ERROR) << "Could not parse input GTFS feed, reason was:";
std::cerr << ex.what() << std::endl; std::cerr << ex.what() << std::endl;
exit(static_cast<int>(RetCode::GTFS_PARSE_ERR)); exit(static_cast<int>(RetCode::GTFS_PARSE_ERR));
@ -167,7 +167,7 @@ int main(int argc, char** argv) {
} }
try { try {
osmBuilder.filterWrite(cfg.osmPath, cfg.writeOsm, opts, box); 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:"; LOG(ERROR) << "Could not parse OSM data, reason was:";
std::cerr << ex.what() << std::endl; std::cerr << ex.what() << std::endl;
exit(static_cast<int>(RetCode::OSM_PARSE_ERR)); exit(static_cast<int>(RetCode::OSM_PARSE_ERR));
@ -276,7 +276,7 @@ int main(int argc, char** argv) {
out.print(ng, fstr); out.print(ng, fstr);
fstr.close(); fstr.close();
} }
} catch (xml::XmlFileException ex) { } catch (const xml::XmlFileException& ex) {
LOG(ERROR) << "Could not parse OSM data, reason was:"; LOG(ERROR) << "Could not parse OSM data, reason was:";
std::cerr << ex.what() << std::endl; std::cerr << ex.what() << std::endl;
exit(static_cast<int>(RetCode::OSM_PARSE_ERR)); exit(static_cast<int>(RetCode::OSM_PARSE_ERR));
@ -291,7 +291,7 @@ int main(int argc, char** argv) {
LOG(INFO) << "Writing output GTFS to " << cfg.outputPath << " ..."; LOG(INFO) << "Writing output GTFS to " << cfg.outputPath << " ...";
pfaedle::gtfs::Writer w; pfaedle::gtfs::Writer w;
w.write(&gtfs[0], cfg.outputPath); w.write(&gtfs[0], cfg.outputPath);
} catch (ad::cppgtfs::WriterException ex) { } catch (const ad::cppgtfs::WriterException& ex) {
LOG(ERROR) << "Could not write final GTFS feed, reason was:"; LOG(ERROR) << "Could not write final GTFS feed, reason was:";
std::cerr << ex.what() << std::endl; std::cerr << ex.what() << std::endl;
exit(static_cast<int>(RetCode::GTFS_WRITE_ERR)); exit(static_cast<int>(RetCode::GTFS_WRITE_ERR));

View file

@ -105,7 +105,7 @@ void HttpServer::handle() {
Req req = getReq(connection); Req req = getReq(connection);
answ = _handler->handle(req, connection); answ = _handler->handle(req, connection);
answ.gzip = gzipSupport(req); answ.gzip = gzipSupport(req);
} catch (HttpErr err) { } catch (const HttpErr& err) {
answ = Answer(err.what(), err.what()); answ = Answer(err.what(), err.what());
} catch (...) { } catch (...) {
// catch everything to make sure the server continues running // catch everything to make sure the server continues running