aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuliano Procida <gprocida@google.com>2023-12-12 17:41:53 +0000
committerGiuliano Procida <gprocida@google.com>2023-12-13 11:25:44 +0000
commitd2a7fe78605e039e97837de6b169b530d2ebee5e (patch)
tree8906296d86e7a8c53ffe5dc6adf3066895132e17
parent69eec5c4f8bf7a40eab270b42fe01e3cbf9a4832 (diff)
downloadstg-d2a7fe78605e039e97837de6b169b530d2ebee5e.tar.gz
error: allow context to be added to Exception objects
PiperOrigin-RevId: 590237148 Change-Id: Ia4c7c4b3514fa6330288e2075724399f99286ef5
-rw-r--r--error.h10
-rw-r--r--stg.cc2
-rw-r--r--stgdiff.cc2
3 files changed, 10 insertions, 4 deletions
diff --git a/error.h b/error.h
index 6eed80e..5ca6c57 100644
--- a/error.h
+++ b/error.h
@@ -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 {
diff --git a/stg.cc b/stg.cc
index 8776d39..82a372e 100644
--- a/stg.cc
+++ b/stg.cc
@@ -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;
}
}
diff --git a/stgdiff.cc b/stgdiff.cc
index 51dda88..18cc733 100644
--- a/stgdiff.cc
+++ b/stgdiff.cc
@@ -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;
}
}