pretending to be const

This commit is contained in:
Ben Burdette 2020-05-07 16:43:36 -06:00
parent e3901638b5
commit 1b801cec40
3 changed files with 23 additions and 7 deletions

View file

@ -43,6 +43,22 @@ int main()
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.
// But this is maybe a heavy format for those.
logger->logEI(

View file

@ -82,10 +82,10 @@ class BaseError : public std::exception
{
protected:
string prefix_; // used for location traces etc.
ErrorInfo err;
mutable ErrorInfo err;
std::optional<string> what_;
const string& calcWhat()
mutable std::optional<string> what_;
const string& calcWhat() const
{
if (what_.has_value())
return *what_;
@ -131,12 +131,12 @@ public:
#ifdef EXCEPTION_NEEDS_THROW_SPEC
~BaseError() throw () { };
const char * what() throw () { return calcWhat().c_str(); }
const char * what() const throw () { return calcWhat().c_str(); }
#else
const char * what() noexcept { return calcWhat().c_str(); }
const char * what() const noexcept override { return calcWhat().c_str(); }
#endif
const string & msg() { return calcWhat(); }
const string & msg() const { return calcWhat(); }
const string & prefix() const { return prefix_; }
BaseError & addPrefix(const FormatOrString & fs);

View file

@ -368,7 +368,7 @@ static void _main(int argc, char * * argv)
shell = drv->queryOutPath() + "/bin/bash";
} catch (Error & e) {
// TODO: append error msg
// TODO: append error msg; warn()?
logError(e.info());
printError("warning: %s; will use bash from your environment", e.what());
shell = "bash";