pretending to be const
This commit is contained in:
parent
e3901638b5
commit
1b801cec40
|
@ -43,6 +43,22 @@ int main()
|
||||||
logError(e.info());
|
logError(e.info());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// current exception
|
||||||
|
try {
|
||||||
|
throw DemoError("DemoError handled as a %1%", "std::exception");
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
const std::exception_ptr &eptr = std::current_exception();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::rethrow_exception(eptr);
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// For completeness sake, info through vomit levels.
|
// For completeness sake, info through vomit levels.
|
||||||
// But this is maybe a heavy format for those.
|
// But this is maybe a heavy format for those.
|
||||||
logger->logEI(
|
logger->logEI(
|
||||||
|
|
|
@ -82,10 +82,10 @@ class BaseError : public std::exception
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
string prefix_; // used for location traces etc.
|
string prefix_; // used for location traces etc.
|
||||||
ErrorInfo err;
|
mutable ErrorInfo err;
|
||||||
|
|
||||||
std::optional<string> what_;
|
mutable std::optional<string> what_;
|
||||||
const string& calcWhat()
|
const string& calcWhat() const
|
||||||
{
|
{
|
||||||
if (what_.has_value())
|
if (what_.has_value())
|
||||||
return *what_;
|
return *what_;
|
||||||
|
@ -131,12 +131,12 @@ public:
|
||||||
|
|
||||||
#ifdef EXCEPTION_NEEDS_THROW_SPEC
|
#ifdef EXCEPTION_NEEDS_THROW_SPEC
|
||||||
~BaseError() throw () { };
|
~BaseError() throw () { };
|
||||||
const char * what() throw () { return calcWhat().c_str(); }
|
const char * what() const throw () { return calcWhat().c_str(); }
|
||||||
#else
|
#else
|
||||||
const char * what() noexcept { return calcWhat().c_str(); }
|
const char * what() const noexcept override { return calcWhat().c_str(); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const string & msg() { return calcWhat(); }
|
const string & msg() const { return calcWhat(); }
|
||||||
const string & prefix() const { return prefix_; }
|
const string & prefix() const { return prefix_; }
|
||||||
BaseError & addPrefix(const FormatOrString & fs);
|
BaseError & addPrefix(const FormatOrString & fs);
|
||||||
|
|
||||||
|
|
|
@ -368,7 +368,7 @@ static void _main(int argc, char * * argv)
|
||||||
shell = drv->queryOutPath() + "/bin/bash";
|
shell = drv->queryOutPath() + "/bin/bash";
|
||||||
|
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
// TODO: append error msg
|
// TODO: append error msg; warn()?
|
||||||
logError(e.info());
|
logError(e.info());
|
||||||
printError("warning: %s; will use bash from your environment", e.what());
|
printError("warning: %s; will use bash from your environment", e.what());
|
||||||
shell = "bash";
|
shell = "bash";
|
||||||
|
|
Loading…
Reference in a new issue