Class thrust::system::system_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
.
Inherits From: std::runtime_error
#include <thrust/system/system_error.h>
class thrust::system::system_error { public: system_error(error_code ec, const std::string & what_arg);
system_error(error_code ec, const char * what_arg);
system_error(error_code ec);
system_error(int ev, const error_category & ecat, const std::string & what_arg);
system_error(int ev, const error_category & ecat, const char * what_arg);
system_error(int ev, const error_category & ecat);
virtual ~system_error();
const error_code & code() const;
const char * what() const; };
Member Functions
Function thrust::system::system_error::system_error
system_error(error_code ec, const std::string & what_arg);
Constructs an object of class system_error
.
Function Parameters:
Postconditions:
code() == ec
.std::string(what()).find(what_arg) != string::npos
.
Function thrust::system::system_error::system_error
system_error(error_code ec, const char * what_arg);
Constructs an object of class system_error
.
Function Parameters:
Postconditions:
code() == ec
.std::string(what()).find(what_arg) != string::npos
.
Function thrust::system::system_error::system_error
system_error(error_code ec);
Constructs an object of class system_error
.
Function Parameters: ec
: The value returned by code()
.
Postconditions: code() == ec
.
Function thrust::system::system_error::system_error
system_error(int ev, const error_category & ecat, const std::string & what_arg);
Constructs an object of class system_error
.
Function Parameters:
ev
The error value used to create anerror_code
.ecat
Theerror_category
used to create anerror_code
.what_arg
A string to include in the result returned bywhat()
.
Postconditions:
code() == error_code(ev, ecat)
.std::string(what()).find(what_arg) != string::npos
.
Function thrust::system::system_error::system_error
system_error(int ev, const error_category & ecat, const char * what_arg);
Constructs an object of class system_error
.
Function Parameters:
ev
The error value used to create anerror_code
.ecat
Theerror_category
used to create anerror_code
.what_arg
A string to include in the result returned bywhat()
.
Postconditions:
code() == error_code(ev, ecat)
.std::string(what()).find(what_arg) != string::npos
.
Function thrust::system::system_error::system_error
system_error(int ev, const error_category & ecat);
Constructs an object of class system_error
.
Function Parameters:
ev
The error value used to create anerror_code
.ecat
Theerror_category
used to create anerror_code
.
Postconditions: code() == error_code(ev, ecat)
.
Function thrust::system::system_error::~system_error
virtual ~system_error();
Destructor does not throw.
Function thrust::system::system_error::code
const error_code & code() const;
Returns an object encoding the error.
Returns: ec
or error_code(ev, ecat)
, from the constructor, as appropriate.
Function thrust::system::system_error::what
const char * what() const;
Returns a human-readable string indicating the nature of the error.
Returns: a string incorporating code().message()
and the arguments supplied in the constructor.