From 5db146ef751507efd4f9556c9a0ab3bb5e88f7c5 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 6 Jan 2017 03:23:20 +0300 Subject: Make use of operator<<(ostream, exception) --- brep/utility | 2 +- load/load.cxx | 15 +++++++-------- migrate/migrate.cxx | 4 ++-- mod/database-module.cxx | 2 +- mod/mod-repository-root.cxx | 4 +++- tests/load/driver.cxx | 2 +- web/apache/service.txx | 2 +- 7 files changed, 16 insertions(+), 15 deletions(-) diff --git a/brep/utility b/brep/utility index dfa10a2..631af7f 100644 --- a/brep/utility +++ b/brep/utility @@ -11,7 +11,7 @@ #include // assert() #include // make_move_iterator() -#include // reverse_iterate() +#include // reverse_iterate(), operator<<(ostream, exception) namespace brep { diff --git a/load/load.cxx b/load/load.cxx index b2c19f3..ee258fa 100644 --- a/load/load.cxx +++ b/load/load.cxx @@ -233,7 +233,7 @@ load_repositories (path p) } catch (const io_error& e) { - cerr << "error: unable to read " << p << ": " << e.what () << endl; + cerr << "error: unable to read " << p << ": " << e << endl; throw failed (); } @@ -298,8 +298,7 @@ repository_info (const options& lo, const string& rl, const cstrings& options) } catch (const process_error& e) { - cerr << "error: unable to execute " << args[0] << ": " << e.what () - << endl; + cerr << "error: unable to execute " << args[0] << ": " << e << endl; if (e.child ()) exit (1); @@ -337,7 +336,7 @@ load_packages (const shared_ptr& rp, database& db) } catch (const io_error& e) { - cerr << "error: unable to read " << p << ": " << e.what () << endl; + cerr << "error: unable to read " << p << ": " << e << endl; throw failed (); } @@ -493,7 +492,7 @@ load_repositories (const shared_ptr& rp, database& db) } catch (const io_error& e) { - cerr << "error: unable to read " << p << ": " << e.what () << endl; + cerr << "error: unable to read " << p << ": " << e << endl; throw failed (); } @@ -938,7 +937,7 @@ certificate_info (const options& lo, catch (const process_error& e) { cerr << "error: unable to fetch certificate information for " - << rl.canonical_name () << ": " << e.what () << endl; + << rl.canonical_name () << ": " << e << endl; // Fall through. } @@ -1094,7 +1093,7 @@ catch (const database_locked&) } catch (const recoverable& e) { - cerr << "database recoverable error: " << e.what () << endl; + cerr << "database recoverable error: " << e << endl; return 3; } catch (const cli::exception& e) @@ -1110,6 +1109,6 @@ catch (const failed&) // catch (const std::exception& e) { - cerr << "error: " << e.what () << endl; + cerr << "error: " << e << endl; return 1; } diff --git a/migrate/migrate.cxx b/migrate/migrate.cxx index 4001bf9..98bdfbd 100644 --- a/migrate/migrate.cxx +++ b/migrate/migrate.cxx @@ -335,7 +335,7 @@ catch (const database_locked&) } catch (const recoverable& e) { - cerr << "database recoverable error: " << e.what () << endl; + cerr << "database recoverable error: " << e << endl; return 3; } catch (const cli::exception& e) @@ -351,6 +351,6 @@ catch (const failed&) // catch (const std::exception& e) { - cerr << "error: " << e.what () << endl; + cerr << "error: " << e << endl; return 1; } diff --git a/mod/database-module.cxx b/mod/database-module.cxx index 8c701b1..6fd5025 100644 --- a/mod/database-module.cxx +++ b/mod/database-module.cxx @@ -41,7 +41,7 @@ namespace brep if (retry_-- > 0) { MODULE_DIAG; - l1 ([&]{trace << e.what () << "; " << retry_ + 1 << " retries left";}); + l1 ([&]{trace << e << "; " << retry_ + 1 << " retries left";}); throw retry (); } diff --git a/mod/mod-repository-root.cxx b/mod/mod-repository-root.cxx index c51c61c..84c1ed1 100644 --- a/mod/mod-repository-root.cxx +++ b/mod/mod-repository-root.cxx @@ -177,7 +177,9 @@ namespace brep // Note that the server_error exception is handled internally by the // module::handle() function call. // - throw runtime_error (string (name) + ": " + e.what ()); + ostringstream os; + os << name << ": " << e; + throw runtime_error (os.str ()); } }; diff --git a/tests/load/driver.cxx b/tests/load/driver.cxx index 6539152..396d89f 100644 --- a/tests/load/driver.cxx +++ b/tests/load/driver.cxx @@ -848,7 +848,7 @@ main (int argc, char* argv[]) // catch (const std::exception& e) { - cerr << e.what () << endl; + cerr << e << endl; return 1; } } diff --git a/web/apache/service.txx b/web/apache/service.txx index 6630fd0..b707f8d 100644 --- a/web/apache/service.txx +++ b/web/apache/service.txx @@ -171,7 +171,7 @@ namespace web { rq.content ( HTTP_INTERNAL_SERVER_ERROR, "text/plain;charset=utf-8") - << e.what (); + << e; return rq.flush (); } -- cgit v1.1