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`.
This commit is contained in:
Kenneth Moreland 2021-03-26 15:42:45 -06:00
parent 210ca76c29
commit eadaf06f0c

@ -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;