1
0
mirror of https://github.com/Zygo/bees.git synced 2025-05-17 13:25:45 +02:00
bees/lib/error.cc
Zygo Blaxell 228747a8f8 lib: fix non-local lambda expression cannot have a capture-default
We got away with this because GCC 4.8 (and apparently every GCC prior
to 9) didn't notice or care, and because there is nothing referenced
inside the lambda function body that isn't accessible from any other
kind of function body (i.e. the capture wasn't needed at all).

GCC 9 now enforces what the C++ standard said all along:  there is
no need to allow capture-default in this case, so it is not.

Fix by removing the offending capture-default.

Fixes: https://github.com/Zygo/bees/issues/112
Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2019-06-12 22:48:06 -04:00

75 lines
1.4 KiB
C++

#include "crucible/error.h"
#include <cstdarg>
#include <iostream>
#include <cxxabi.h>
namespace crucible {
using namespace std;
static
string
analyze_exception(const exception &e)
{
// Let's ignore all the potential memory allocation exceptions for now, K?
ostringstream oss;
int status;
char *realname = abi::__cxa_demangle(typeid(e).name(), 0, 0, &status);
oss << "exception type ";
// This is questionable since anything that would cause
// cxa_demangle to fail will probably cause an exception anyway.
if (realname) {
oss << realname;
free(realname);
} else {
oss << typeid(e).name();
}
oss << ": " << e.what();
return oss.str();
}
// FIXME: could probably avoid some of these levels of indirection
static
function<void(string s)> current_catch_explainer = [](string s) {
cerr << s << endl;
};
void
set_catch_explainer(function<void(string s)> f)
{
current_catch_explainer = f;
}
void
default_catch_explainer(string s)
{
current_catch_explainer(s);
}
int
catch_all(const function<void()> &f, const function<void(string)> &explainer)
{
try {
f();
return 0;
} catch (const exception &e) {
explainer(analyze_exception(e));
return 1;
}
}
void
catch_and_explain(const function<void()> &f, const function<void(string)> &explainer)
{
try {
f();
} catch (const exception &e) {
explainer(analyze_exception(e));
throw;
}
}
};