| 26 | }; |
| 27 | |
| 28 | class Error { |
| 29 | public: |
| 30 | Error(); |
| 31 | explicit Error(StringBox message); |
| 32 | explicit Error(const std::string_view& message); |
| 33 | explicit Error(const char* message); |
| 34 | Error(StringBox message, StringBox stackTrace, const Error* cause); |
| 35 | Error(StringBox message, int32_t errorCode); |
| 36 | Error(Ref<ErrorStorage> storage); |
| 37 | |
| 38 | bool isEmpty() const; |
| 39 | bool hasStack() const; |
| 40 | |
| 41 | std::string toString() const; |
| 42 | StringBox toStringBox() const; |
| 43 | |
| 44 | /** |
| 45 | Return the outer message in the Error hierarchy. |
| 46 | */ |
| 47 | const StringBox& getMessage() const noexcept; |
| 48 | |
| 49 | /** |
| 50 | Return the outer stack in the Error hierarchy. |
| 51 | */ |
| 52 | const StringBox& getStack() const noexcept; |
| 53 | |
| 54 | std::optional<Error> getCause() const noexcept; |
| 55 | |
| 56 | /** |
| 57 | Return the error code associated with this error. |
| 58 | Returns 0 if no specific error code was set. |
| 59 | */ |
| 60 | int32_t getErrorCode() const noexcept; |
| 61 | |
| 62 | bool operator==(const Error& other) const noexcept; |
| 63 | bool operator!=(const Error& other) const noexcept; |
| 64 | |
| 65 | Error rethrow(const StringBox& message) const; |
| 66 | Error rethrow(std::string_view message) const; |
| 67 | Error rethrow(const Error& error) const; |
| 68 | |
| 69 | /** |
| 70 | Return an error message that contains a merged message from all the causes, and contains the first resolved stack |
| 71 | */ |
| 72 | Error flatten() const; |
| 73 | |
| 74 | size_t hash() const; |
| 75 | |
| 76 | const Ref<ErrorStorage>& getStorage() const; |
| 77 | |
| 78 | private: |
| 79 | Ref<ErrorStorage> _storage; |
| 80 | |
| 81 | std::string toString(bool includeCauses) const; |
| 82 | }; |
| 83 | |
| 84 | std::ostream& operator<<(std::ostream& os, const Error& error); |
| 85 |
no outgoing calls
no test coverage detected