From eadaf06f0c0a4f18d4b207ba0486847941587256 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Fri, 26 Mar 2021 15:42:45 -0600 Subject: [PATCH] Set what string in Error::SetMessage `vtkm::cont::Error` inherits from `std::exception`. As such, it has a special `what` string that reports an error message in a standard way. This is particularly useful when a `vtkm::cont::Error` exception remains uncaught because the system will print the `what` string before crashing. Unfortunately, the `what` string was only being set in the `Error` constructor that took a message. That is a problem for subclasses like `ErrorCuda` that used the default constructor and then used `SetMessage`. The `what` string did not get set in this case. Change the behavior to capture the stack trace in the default constructor and update the `what` string if a subclass uses `SetMessage`. --- vtkm/cont/Error.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/vtkm/cont/Error.h b/vtkm/cont/Error.h index 15e56e44d..9929fcfbf 100644 --- a/vtkm/cont/Error.h +++ b/vtkm/cont/Error.h @@ -56,7 +56,12 @@ public: bool GetIsDeviceIndependent() const { return this->IsDeviceIndependent; } protected: - Error() {} + Error() + : StackTrace(vtkm::cont::GetStackTrace(1)) + , What("Undescribed error\n" + StackTrace) + , IsDeviceIndependent(false) + { + } Error(const std::string& message, bool is_device_independent = false) : Message(message) , StackTrace(vtkm::cont::GetStackTrace(1)) @@ -65,7 +70,11 @@ protected: { } - void SetMessage(const std::string& message) { this->Message = message; } + void SetMessage(const std::string& message) + { + this->Message = message; + this->What = this->Message + "\n" + this->StackTrace; + } private: std::string Message;