2014-02-10 19:53:03 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2014-02-10 19:53:03 +00:00
|
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the above copyright notice for more information.
|
|
|
|
//============================================================================
|
2014-03-07 15:19:09 +00:00
|
|
|
#ifndef vtk_m_cont_Error_h
|
|
|
|
#define vtk_m_cont_Error_h
|
2014-02-10 19:53:03 +00:00
|
|
|
|
|
|
|
// Note that this class and (most likely) all of its subclasses are not
|
|
|
|
// templated. If there is any reason to create a VTKm control library,
|
|
|
|
// this class and its subclasses should probably go there.
|
|
|
|
|
2017-01-09 20:34:35 +00:00
|
|
|
#include <exception>
|
2014-02-10 19:53:03 +00:00
|
|
|
#include <string>
|
|
|
|
|
2018-08-30 17:29:36 +00:00
|
|
|
#include <vtkm/cont/Logging.h>
|
|
|
|
|
2018-02-22 16:34:08 +00:00
|
|
|
#include <vtkm/internal/ExportMacros.h>
|
2017-01-09 20:34:35 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
2014-02-10 19:53:03 +00:00
|
|
|
|
2017-04-13 18:06:33 +00:00
|
|
|
VTKM_SILENCE_WEAK_VTABLE_WARNING_START
|
|
|
|
|
2014-02-10 19:53:03 +00:00
|
|
|
/// The superclass of all exceptions thrown by any VTKm function or method.
|
|
|
|
///
|
2016-12-19 15:47:50 +00:00
|
|
|
class VTKM_ALWAYS_EXPORT Error : public std::exception
|
2014-02-10 19:53:03 +00:00
|
|
|
{
|
|
|
|
public:
|
2016-04-21 14:23:34 +00:00
|
|
|
//See note about GetMessage macro below.
|
|
|
|
#ifndef GetMessage
|
2017-05-18 14:29:41 +00:00
|
|
|
const std::string& GetMessage() const { return this->Message; }
|
2016-04-21 14:23:34 +00:00
|
|
|
#endif
|
2019-07-31 21:51:35 +00:00
|
|
|
const std::string& GetStackTrace() const { return this->StackTrace; }
|
2014-02-10 19:53:03 +00:00
|
|
|
|
2014-05-19 18:23:30 +00:00
|
|
|
//GetMessage is a macro defined by <windows.h> to redirrect to
|
|
|
|
//GetMessageA or W depending on if you are using ansi or unicode.
|
|
|
|
//To get around this we make our own A/W variants on windows.
|
|
|
|
#ifdef _WIN32
|
2017-05-18 14:29:41 +00:00
|
|
|
const std::string& GetMessageA() const { return this->Message; }
|
|
|
|
const std::string& GetMessageW() const { return this->Message; }
|
2014-05-19 18:23:30 +00:00
|
|
|
#endif
|
|
|
|
|
2017-01-09 20:34:35 +00:00
|
|
|
// For std::exception compatibility:
|
2019-09-04 19:03:30 +00:00
|
|
|
const char* what() const noexcept override { return this->What.c_str(); }
|
2017-01-09 20:34:35 +00:00
|
|
|
|
2018-04-03 18:34:16 +00:00
|
|
|
/// Returns true if this exception is device independent. For exceptions that
|
|
|
|
/// are not device independent, `vtkm::TryExecute`, for example, may try
|
|
|
|
/// executing the code on other available devices.
|
|
|
|
bool GetIsDeviceIndependent() const { return this->IsDeviceIndependent; }
|
|
|
|
|
2014-02-10 19:53:03 +00:00
|
|
|
protected:
|
2021-03-26 21:42:45 +00:00
|
|
|
Error()
|
|
|
|
: StackTrace(vtkm::cont::GetStackTrace(1))
|
|
|
|
, What("Undescribed error\n" + StackTrace)
|
|
|
|
, IsDeviceIndependent(false)
|
|
|
|
{
|
|
|
|
}
|
2018-04-03 18:34:16 +00:00
|
|
|
Error(const std::string& message, bool is_device_independent = false)
|
2017-05-18 14:29:41 +00:00
|
|
|
: Message(message)
|
2019-07-31 21:51:35 +00:00
|
|
|
, StackTrace(vtkm::cont::GetStackTrace(1))
|
2019-09-04 19:03:30 +00:00
|
|
|
, What(Message + "\n" + StackTrace)
|
2018-04-03 18:34:16 +00:00
|
|
|
, IsDeviceIndependent(is_device_independent)
|
2014-02-11 21:20:30 +00:00
|
|
|
{
|
2014-02-10 19:53:03 +00:00
|
|
|
}
|
|
|
|
|
2021-03-26 21:42:45 +00:00
|
|
|
void SetMessage(const std::string& message)
|
|
|
|
{
|
|
|
|
this->Message = message;
|
|
|
|
this->What = this->Message + "\n" + this->StackTrace;
|
|
|
|
}
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2014-02-10 19:53:03 +00:00
|
|
|
private:
|
|
|
|
std::string Message;
|
2019-07-31 21:51:35 +00:00
|
|
|
std::string StackTrace;
|
2019-09-04 19:03:30 +00:00
|
|
|
std::string What;
|
2018-04-03 18:34:16 +00:00
|
|
|
bool IsDeviceIndependent;
|
2014-02-10 19:53:03 +00:00
|
|
|
};
|
|
|
|
|
2017-04-13 18:06:33 +00:00
|
|
|
VTKM_SILENCE_WEAK_VTABLE_WARNING_END
|
2014-02-10 19:53:03 +00:00
|
|
|
}
|
|
|
|
} // namespace vtkm::cont
|
|
|
|
|
2014-06-11 16:43:36 +00:00
|
|
|
#endif //vtk_m_cont_Error_h
|