From adddeca028100355a922cc4e45226ce7f18420c9 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 22 Mar 2017 00:44:52 +0300 Subject: Make use of throw_generic_error() --- build2/b.cxx | 2 +- build2/cc/windows-rpath.cxx | 8 ++++++++ build2/scheduler.cxx | 2 +- build2/scheduler.txx | 2 +- build2/test/script/builtin.cxx | 12 ++++++------ build2/test/script/runner.cxx | 4 ++-- build2/utility | 2 ++ 7 files changed, 21 insertions(+), 11 deletions(-) diff --git a/build2/b.cxx b/build2/b.cxx index 60ac2f0..89c3d9c 100644 --- a/build2/b.cxx +++ b/build2/b.cxx @@ -104,7 +104,7 @@ main (int argc, char* argv[]) #ifndef _WIN32 if (signal (SIGPIPE, SIG_IGN) == SIG_ERR) fail << "unable to ignore broken pipe (SIGPIPE) signal: " - << system_error (errno, system_category ()); // Sanitize. + << system_error (errno, generic_category ()); // Sanitize. #endif // Parse the command line. We want to be able to specify options, vars, diff --git a/build2/cc/windows-rpath.cxx b/build2/cc/windows-rpath.cxx index 383663f..0b34963 100644 --- a/build2/cc/windows-rpath.cxx +++ b/build2/cc/windows-rpath.cxx @@ -315,6 +315,10 @@ namespace build2 } catch (const system_error& e) { + // Make sure that the error denotes errno portable code. + // + assert (e.code ().category () == generic_category ()); + int c (e.code ().value ()); if (c != EPERM && c != ENOSYS) @@ -330,6 +334,10 @@ namespace build2 } catch (const system_error& e) { + // Make sure the error reflects errno portable code. + // + assert (e.code ().category () == generic_category ()); + int c (e.code ().value ()); if (c != EPERM && c != ENOSYS) diff --git a/build2/scheduler.cxx b/build2/scheduler.cxx index 9a3003b..a453cb3 100644 --- a/build2/scheduler.cxx +++ b/build2/scheduler.cxx @@ -100,7 +100,7 @@ namespace build2 ready_--; if (shutdown_) - throw system_error (ECANCELED, system_category ()); + throw_generic_error (ECANCELED); active_++; } diff --git a/build2/scheduler.txx b/build2/scheduler.txx index 684409c..b62acdb 100644 --- a/build2/scheduler.txx +++ b/build2/scheduler.txx @@ -38,7 +38,7 @@ namespace build2 lock ql (tq->mutex); if (tq->shutdown) - throw system_error (ECANCELED, std::system_category ()); + throw_generic_error (ECANCELED); if (task_data* td = push (*tq)) { diff --git a/build2/test/script/builtin.cxx b/build2/test/script/builtin.cxx index 5b011e3..6f63551 100644 --- a/build2/test/script/builtin.cxx +++ b/build2/test/script/builtin.cxx @@ -307,7 +307,7 @@ namespace build2 try { if (try_mkdir (to) == mkdir_status::already_exists) - throw system_error (EEXIST, system_category ()); + throw_generic_error (EEXIST); if (cleanup) sp.clean ({cleanup_type::always, to}, true); @@ -628,7 +628,7 @@ namespace build2 sp.clean ({cleanup_type::always, p}, true); } else // == mkdir_status::already_exists - throw system_error (EEXIST, system_category ()); + throw_generic_error (EEXIST); } catch (const system_error& e) { @@ -748,7 +748,7 @@ namespace build2 try_rmdir_r (d); } else if (try_rmfile (p) == rmfile_status::not_exist && !force) - throw system_error (ENOENT, system_category ()); + throw_generic_error (ENOENT); } catch (const system_error& e) { @@ -848,9 +848,9 @@ namespace build2 rmdir_status s (try_rmdir (p)); if (s == rmdir_status::not_empty) - throw system_error (ENOTEMPTY, system_category ()); + throw_generic_error (ENOTEMPTY); else if (s == rmdir_status::not_exist && !force) - throw system_error (ENOENT, system_category ()); + throw_generic_error (ENOENT); } catch (const system_error& e) { @@ -1304,7 +1304,7 @@ namespace build2 #else if (_utime (p.string ().c_str (), nullptr) == -1) #endif - throw system_error (errno, system_category ()); + throw_generic_error (errno); } else if (!entry_exists (p)) { diff --git a/build2/test/script/runner.cxx b/build2/test/script/runner.cxx index 464c1f9..3c5f8ba 100644 --- a/build2/test/script/runner.cxx +++ b/build2/test/script/runner.cxx @@ -1171,7 +1171,7 @@ namespace build2 if (ifd.get () == -1) // @@ TMP throw io_error ( - error_code (errno, system_category ()).message ()); + error_code (errno, generic_category ()).message ()); } catch (const io_error& e) { @@ -1296,7 +1296,7 @@ namespace build2 if (fd.get () == -1) // @@ TMP throw io_error ( - error_code (errno, system_category ()).message ()); + error_code (errno, generic_category ()).message ()); } catch (const io_error& e) { diff --git a/build2/utility b/build2/utility index 0c129c4..2880bb5 100644 --- a/build2/utility +++ b/build2/utility @@ -60,6 +60,8 @@ namespace build2 using butl::exception_guard; using butl::make_exception_guard; + using butl::throw_generic_error; + // Basic string utilities. // -- cgit v1.1