mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 19:46:02 +01:00
libmain: Catch logger exceptions in handleExceptions
Avoid std::terminate in case logging code also throws.
This commit is contained in:
parent
b4bea57667
commit
90d1ff4805
1 changed files with 27 additions and 22 deletions
|
|
@ -315,6 +315,7 @@ int handleExceptions(const std::string & programName, std::function<void()> fun)
|
||||||
ErrorInfo::programName = baseNameOf(programName);
|
ErrorInfo::programName = baseNameOf(programName);
|
||||||
|
|
||||||
std::string error = ANSI_RED "error:" ANSI_NORMAL " ";
|
std::string error = ANSI_RED "error:" ANSI_NORMAL " ";
|
||||||
|
try {
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
fun();
|
fun();
|
||||||
|
|
@ -342,6 +343,10 @@ int handleExceptions(const std::string & programName, std::function<void()> fun)
|
||||||
printError(error + e.what());
|
printError(error + e.what());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
} catch (...) {
|
||||||
|
/* In case logger also throws just give up. */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue