From 93ebb3e7dfb75ce23c1fb46d8e70208a2bad0c02 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Tue, 28 May 2024 16:09:33 +0200 Subject: [PATCH] util.{hh,cc}: Move ignoreException to error.{hh,cc} Change-Id: Iae6464217a55c313a983e5c651b26a4a1e446706 --- src/libutil/current-process.cc | 2 +- src/libutil/error.cc | 13 +++++++++++++ src/libutil/error.hh | 6 ++++++ src/libutil/util.cc | 12 ------------ src/libutil/util.hh | 7 ------- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/libutil/current-process.cc b/src/libutil/current-process.cc index f9a08685f..c64dd1e0d 100644 --- a/src/libutil/current-process.cc +++ b/src/libutil/current-process.cc @@ -1,9 +1,9 @@ #include "current-process.hh" +#include "error.hh" #include "file-system.hh" #include "logging.hh" #include "namespaces.hh" #include "signals.hh" -#include "util.hh" #include "strings.hh" #ifdef __APPLE__ diff --git a/src/libutil/error.cc b/src/libutil/error.cc index f780aabef..1a294bf08 100644 --- a/src/libutil/error.cc +++ b/src/libutil/error.cc @@ -417,4 +417,17 @@ std::ostream & showErrorInfo(std::ostream & out, const ErrorInfo & einfo, bool s return out; } +void ignoreException(Verbosity lvl) +{ + /* Make sure no exceptions leave this function. + printError() also throws when remote is closed. */ + try { + try { + throw; + } catch (std::exception & e) { + printMsg(lvl, "error (ignored): %1%", e.what()); + } + } catch (...) { } +} + } diff --git a/src/libutil/error.hh b/src/libutil/error.hh index 323365d65..0884f9f32 100644 --- a/src/libutil/error.hh +++ b/src/libutil/error.hh @@ -202,4 +202,10 @@ public: } }; +/** + * Exception handling in destructors: print an error message, then + * ignore the exception. + */ +void ignoreException(Verbosity lvl = lvlError); + } diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 6d6e55ad1..d9bd71b5f 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -70,18 +70,6 @@ namespace nix { -void ignoreException(Verbosity lvl) -{ - /* Make sure no exceptions leave this function. - printError() also throws when remote is closed. */ - try { - try { - throw; - } catch (std::exception & e) { - printMsg(lvl, "error (ignored): %1%", e.what()); - } - } catch (...) { } -} ////////////////////////////////////////////////////////////////////// diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 867f0a80d..c5ca12650 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -39,13 +39,6 @@ struct Source; extern const std::string nativeSystem; -/** - * Exception handling in destructors: print an error message, then - * ignore the exception. - */ -void ignoreException(Verbosity lvl = lvlError); - - /** * Get a value for the specified key from an associate container.