107 std::source_location location;
108 std::optional<std::string> description;
117 std::shared_ptr<std::list<AsyncTraceFrame>> _asyncTrace;
120 std::shared_ptr<const std::list<AsyncTraceFrame>> asyncTrace()
const
126 addAsyncTrace(std::source_location loc, std::optional<std::string> description = std::nullopt)
129 _asyncTrace = std::make_shared<std::list<AsyncTraceFrame>>();
131 _asyncTrace->push_back(AsyncTraceFrame{loc, std::move(description)});
147 mutable std::optional<std::string>
what_;
151 const std::string &
calcWhat()
const;
154 BaseError(
const BaseError &) =
default;
156 BaseError & operator=(BaseError
const & rhs) =
default;
158 template<
typename...
Args>
159 BaseError(
unsigned int status,
const Args & ... args)
160 : err { .level = lvlError, .msg =
HintFmt(args...), .status = status }
163 template<
typename...
Args>
164 explicit BaseError(
const std::string & fs,
const Args & ... args)
165 : err { .level = lvlError, .msg =
HintFmt(fs, args...) }
168 template<
typename... Args>
169 BaseError(
const Suggestions & sug,
const Args & ... args)
170 : err { .level = lvlError, .msg = HintFmt(args...), .suggestions = sug }
173 BaseError(HintFmt hint)
174 : err { .level = lvlError, .msg = hint }
177 BaseError(ErrorInfo && e)
181 BaseError(
const ErrorInfo & e)
185 const char * what() const noexcept
override {
return calcWhat().c_str(); }
186 const std::string & msg()
const {
return calcWhat(); }
187 const ErrorInfo & info()
const {
calcWhat();
return err; }
189 void withExitStatus(
unsigned int status)
194 void atPos(std::shared_ptr<Pos> pos) {
198 void pushTrace(Trace trace)
200 err.traces.push_front(trace);
203 template<
typename... Args>
204 void addTrace(std::shared_ptr<Pos> && e, std::string_view fs,
const Args & ... args)
206 addTrace(std::move(e), HintFmt(std::string(fs), args...));
209 void addTrace(std::shared_ptr<Pos> && e, HintFmt hint);
211 bool hasTrace()
const {
return !err.traces.empty(); }
213 const ErrorInfo & info() {
return err; };
237 std::shared_ptr<std::string> _what;
240 const std::exception_ptr inner;
241 const std::type_info & innerType;
243 explicit ForeignException(
const std::exception & inner)
244 : _what(std::make_shared<std::string>(inner.what()))
245 , inner(std::make_exception_ptr(inner))
246 , innerType(
typeid(inner))
253 std::rethrow_exception(inner);
271 return as<E>() !=
nullptr;
274 const char * what()
const noexcept override
276 return _what->c_str();
280class SysError :
public Error
285 template<
typename...
Args>
286 SysError(
int errNo_,
const Args & ... args)
294 template<
typename...
Args>
295 SysError(std::error_code ec,
const Args & ... args)
303 template<
typename...
Args>
304 SysError(
const Args & ... args)
305 : SysError(errno, args ...)