diff options
author | Giuliano Procida <gprocida@google.com> | 2023-12-12 17:41:53 +0000 |
---|---|---|
committer | Giuliano Procida <gprocida@google.com> | 2023-12-13 11:25:44 +0000 |
commit | d2a7fe78605e039e97837de6b169b530d2ebee5e (patch) | |
tree | 8906296d86e7a8c53ffe5dc6adf3066895132e17 | |
parent | 69eec5c4f8bf7a40eab270b42fe01e3cbf9a4832 (diff) | |
download | stg-d2a7fe78605e039e97837de6b169b530d2ebee5e.tar.gz |
error: allow context to be added to Exception objects
PiperOrigin-RevId: 590237148
Change-Id: Ia4c7c4b3514fa6330288e2075724399f99286ef5
-rw-r--r-- | error.h | 10 | ||||
-rw-r--r-- | stg.cc | 2 | ||||
-rw-r--r-- | stgdiff.cc | 2 |
3 files changed, 10 insertions, 4 deletions
@@ -32,14 +32,20 @@ namespace stg { class Exception : public std::exception { public: - explicit Exception(const std::string& message) : message_(message) {} + explicit Exception(const std::string& message) { + Add(message); + } const char* what() const noexcept(true) final { return message_.c_str(); } + void Add(const std::string& message) { + (message_ += message) += '\n'; + } + private: - const std::string message_; + std::string message_; }; class Check { @@ -234,7 +234,7 @@ int main(int argc, char* argv[]) { } return 0; } catch (const stg::Exception& e) { - std::cerr << e.what() << '\n'; + std::cerr << e.what(); return 1; } } @@ -270,7 +270,7 @@ int main(int argc, char* argv[]) { } return status; } catch (const stg::Exception& e) { - std::cerr << e.what() << '\n'; + std::cerr << e.what(); return 1; } } |