thrust::system::system_error

Defined in thrust/system/system_error.h

class system_error : public runtime_error

The class system_error describes an exception object used to report error conditions that have an associated error_code. Such error conditions typically originate from the operating system or other low-level application program interfaces.

Thrust uses system_error to report the error codes returned from device backends such as the CUDA runtime.

The following code listing demonstrates how to catch a system_error to recover from an error.

#include <thrust/device_vector.h>
#include <thrust/system.h>
#include <thrust/sort.h>

void terminate_gracefully()
{
  // application-specific termination code here
  ...
}

int main()
{
  try
  {
    thrust::device_vector<float> vec;
    thrust::sort(vec.begin(), vec.end());
  }
  catch(thrust::system_error e)
  {
    std::cerr << "Error inside sort: " << e.what() << std::endl;
    terminate_gracefully();
  }

  return 0;
}

Note

If an error represents an out-of-memory condition, implementations are encouraged to throw an exception object of type std::bad_alloc rather than system_error.

Public Functions

inline system_error(error_code ec, const std::string &what_arg)

Constructs an object of class system_error.

Parameters
  • ec – The value returned by code().

  • what_arg – A string to include in the result returned by what().

Post

code() == ec.

Post

std::string(what()).find(what_arg) != string::npos.

inline system_error(error_code ec, const char *what_arg)

Constructs an object of class system_error.

Parameters
  • ec – The value returned by code().

  • what_arg – A string to include in the result returned by what().

Post

code() == ec.

Post

std::string(what()).find(what_arg) != string::npos.

inline system_error(error_code ec)

Constructs an object of class system_error.

Parameters

ec – The value returned by code().

Post

code() == ec.

inline system_error(int ev, const error_category &ecat, const std::string &what_arg)

Constructs an object of class system_error.

Parameters
Post

code() == error_code(ev, ecat).

Post

std::string(what()).find(what_arg) != string::npos.

inline system_error(int ev, const error_category &ecat, const char *what_arg)

Constructs an object of class system_error.

Parameters
Post

code() == error_code(ev, ecat).

Post

std::string(what()).find(what_arg) != string::npos.

inline system_error(int ev, const error_category &ecat)

Constructs an object of class system_error.

Parameters
Post

code() == error_code(ev, ecat).

inline virtual ~system_error() noexcept

Destructor does not throw.

inline const error_code &code() const noexcept

Returns an object encoding the error.

Returns

ec or error_code(ev, ecat), from the constructor, as appropriate.

inline const char *what() const noexcept

Returns a human-readable string indicating the nature of the error.

Returns

a string incorporating code().message() and the arguments supplied in the constructor.