Google Cloud C++ Client 2.10.1
C++ Client Library for Google Cloud Platform
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
google::cloud::Status Class Reference

Represents success or an error with info about the error. More...

#include <google/cloud/status.h>

Public Member Functions

 Status ()
 Default constructor, initializes to StatusCode::kOk. More...
 
 ~Status ()
 Destructor. More...
 
 Status (StatusCode code, std::string message, ErrorInfo info={})
 Construct from a status code, message and (optional) error info. More...
 
bool ok () const
 Returns true if the status code is StatusCode::kOk. More...
 
StatusCode code () const
 Returns the status code. More...
 
std::string const & message () const
 Returns the message associated with the status. More...
 
ErrorInfo const & error_info () const
 Returns the additional error info associated with the status. More...
 
Copy construction and assignment.
 Status (Status const &)
 
Statusoperator= (Status const &)
 
Move construction and assignment.
 Status (Status &&) noexcept
 
Statusoperator= (Status &&) noexcept
 

Friends

bool operator== (Status const &a, Status const &b)
 
bool operator!= (Status const &a, Status const &b)
 

Detailed Description

Represents success or an error with info about the error.

This class is typically used to indicate whether or not a function or other operation completed successfully. Success is indicated by an "OK" status. OK statuses will have .code() == StatusCode::kOk and .ok() == true, with all other properties having empty values. All OK statuses are equal. Any non-OK Status is considered an error. Users can inspect the error using the member functions, or they can simply stream the Status object, and it will print itself in some human readable way (the streamed format may change over time and you should not depend on the specific format of a streamed Status object remaining unchanged).

This is a regular value type that can be copied, moved, compared for equality, and streamed.

Constructor & Destructor Documentation

◆ Status() [1/4]

google::cloud::Status::Status ( )

Default constructor, initializes to StatusCode::kOk.

◆ ~Status()

google::cloud::Status::~Status ( )

Destructor.

◆ Status() [2/4]

google::cloud::Status::Status ( Status const &  )

◆ Status() [3/4]

google::cloud::Status::Status ( Status &&  )
noexcept

◆ Status() [4/4]

google::cloud::Status::Status ( StatusCode  code,
std::string  message,
ErrorInfo  info = {} 
)
explicit

Construct from a status code, message and (optional) error info.

Parameters
codethe status code for the new Status.
messagethe message for the new Status, ignored if code is StatusCode::kOk.
infothe ErrorInfo for the new Status, ignored if code is SStatusCode::kOk.

Member Function Documentation

◆ code()

StatusCode google::cloud::Status::code ( ) const

Returns the status code.

◆ error_info()

ErrorInfo const & google::cloud::Status::error_info ( ) const

Returns the additional error info associated with the status.

This is always a default-constructed error info if code() is StatusCode::kOk.

◆ message()

std::string const & google::cloud::Status::message ( ) const

Returns the message associated with the status.

This is always empty if code() is StatusCode::kOk.

◆ ok()

bool google::cloud::Status::ok ( ) const
inline

Returns true if the status code is StatusCode::kOk.

◆ operator=() [1/2]

Status & google::cloud::Status::operator= ( Status &&  )
noexcept

◆ operator=() [2/2]

Status & google::cloud::Status::operator= ( Status const &  )

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( Status const &  a,
Status const &  b 
)
friend

◆ operator==

bool operator== ( Status const &  a,
Status const &  b 
)
friend