Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
diagnostic_error.hpp
Go to the documentation of this file.
1#pragma once
2
9#include <uni20/config.hpp>
10
11#include <optional>
12#include <source_location>
13#include <stdexcept>
14#include <string>
15#include <utility>
16
17#if UNI20_HAS_STACKTRACE
18#include <stacktrace>
19#endif
20
21namespace uni20
22{
23
25class diagnostic_error : public std::runtime_error {
26 public:
28 explicit diagnostic_error(std::string message) : std::runtime_error(std::move(message)) {}
29
31 void set_source_location(std::source_location where) noexcept { source_location_ = where; }
32
34 [[nodiscard]] std::optional<std::source_location> const& source_location() const noexcept
35 {
36 return source_location_;
37 }
38
39#if UNI20_HAS_STACKTRACE
41 void set_stacktrace(std::stacktrace stacktrace) { stacktrace_ = std::move(stacktrace); }
42
44 [[nodiscard]] std::optional<std::stacktrace> const& stacktrace() const noexcept { return stacktrace_; }
45#endif
46
47 private:
48 std::optional<std::source_location> source_location_;
49#if UNI20_HAS_STACKTRACE
50 std::optional<std::stacktrace> stacktrace_;
51#endif
52};
53
54} // namespace uni20
Base class for exceptions raised through Uni20's diagnostic boundary.
Definition diagnostic_error.hpp:25
std::optional< std::source_location > const & source_location() const noexcept
Return the attached source location, if any.
Definition diagnostic_error.hpp:34
void set_source_location(std::source_location where) noexcept
Attach the source location at which the exception is raised.
Definition diagnostic_error.hpp:31
diagnostic_error(std::string message)
Construct an exception with its concise plain-text message.
Definition diagnostic_error.hpp:28
Definition qnum.hpp:403
Definition async/async.hpp:26