Commit cebe6820 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

add `vtkm::cont::ErrorFilterExecution`

Adding a new exception type `vtkm::cont::ErrorFilterExecution`. Unlike
existing exceptions, when thrown in `TryExecute`, this exception causes
the call to not attempt to execute on any other devices and let it be
thrown so that the application can catch it.
parent 68d43a61
......@@ -74,6 +74,7 @@ set(headers
ErrorBadDevice.h
ErrorBadType.h
ErrorBadValue.h
ErrorFilterExecution.h
ErrorExecution.h
ErrorInternal.h
Field.h
......
......@@ -57,10 +57,16 @@ public:
// For std::exception compatibility:
const char* what() const noexcept override { return this->Message.c_str(); }
/// 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; }
protected:
Error() {}
Error(const std::string message)
Error(const std::string& message, bool is_device_independent = false)
: Message(message)
, IsDeviceIndependent(is_device_independent)
{
}
......@@ -68,6 +74,7 @@ protected:
private:
std::string Message;
bool IsDeviceIndependent;
};
VTKM_SILENCE_WEAK_VTABLE_WARNING_END
......
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
// 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.
//
// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_cont_ErrorFilterExecution_h
#define vtk_m_cont_ErrorFilterExecution_h
#include <vtkm/cont/Error.h>
namespace vtkm
{
namespace cont
{
VTKM_SILENCE_WEAK_VTABLE_WARNING_START
/// This class is primarily intended to filters to throw in the control
/// environment to indicate an execution failure due to misconfiguration e.g.
/// incorrect parameters, etc. This is a device independent exception i.e. when
/// thrown, unlike most other exceptions, VTK-m will not try to re-execute the
/// filter on another available device.
class VTKM_ALWAYS_EXPORT ErrorFilterExecution : public vtkm::cont::Error
{
public:
ErrorFilterExecution(const std::string& message)
: Error(message, /*is_device_independent=*/true)
{
}
};
VTKM_SILENCE_WEAK_VTABLE_WARNING_END
}
} // namespace vtkm::cont
#endif
......@@ -21,6 +21,7 @@
#include <vtkm/cont/ErrorBadAllocation.h>
#include <vtkm/cont/ErrorBadType.h>
#include <vtkm/cont/ErrorBadValue.h>
#include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/cont/TryExecute.h>
namespace vtkm
......@@ -65,6 +66,11 @@ void HandleTryExecuteException(vtkm::Int8 deviceId,
}
catch (vtkm::cont::Error& e)
{
if (e.GetIsDeviceIndependent())
{
// re-throw the exception as it's a device-independent exception.
throw;
}
//general errors should be caught and let us try the next device adapter.
std::cerr << "exception is: " << e.GetMessage() << std::endl;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment