MongoDB C++ Driver legacy-1.1.2
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
mongo::Status Class Reference

Status represents an error state or the absence thereof. More...

#include <status.h>

Public Member Functions

 Status (ErrorCodes::Error code, const std::string &reason, int location=0)
 Builds an error status given the error code, a textual description of what caused the error, and a unique position in the where the error occurred (similar to an assert number)
 
bool compare (const Status &other) const
 Returns true if 'other's error code and location are equal/different to this instance's.
 
bool compareCode (const ErrorCodes::Error other) const
 Returns true if 'other's error code is equal/different to this instance's.
 

Detailed Description

Status represents an error state or the absence thereof.

A Status uses the standardized error codes – from file 'error_codes.h' – to determine an error's cause. It further clarifies the error with a textual description. Optionally, a Status may also have an error location number, which should be a unique, grep-able point in the code base (including assert numbers).

Example usage:

Status sumAB(int a, int b, int* c) { if (overflowIfSum(a,b)) { return Status(ErrorCodes::ERROR_OVERFLOW, "overflow in sumAB", 16494); }

*c = a+b; return Status::OK(); }

TODO: expand base/error_codes.h to capture common errors in current code TODO: generate base/error_codes.h out of a description file TODO: check 'location' duplicates against assert numbers

Member Function Documentation

◆ compare()

bool mongo::Status::compare ( const Status other) const

Returns true if 'other's error code and location are equal/different to this instance's.

Otherwise returns false.

◆ compareCode()

bool mongo::Status::compareCode ( const ErrorCodes::Error  other) const

Returns true if 'other's error code is equal/different to this instance's.

Otherwise returns false.


The documentation for this class was generated from the following files: