Grabba Driver for Android
Unified driver for Grabba devices on the Android operating system
ErrorCode Class Reference

Description

Representation of error codes and messages used throughout the Android APIs.

For operations performing communications (directly or indirectly), or any other activities in which error cases are anticipated, this class is used to notify the caller whether the operation completed successfully or whether an error was detected.

Internally it stores an error code (or Code.NO_ERROR if everything is OK) plus an error message; these are both set when an error is detected and can be queried later on.

Most methods taking a parameter of this class support chaining - that is, they will check the state before proceeding, and then only proceed if it is NO_ERROR. This allows chaining of consecutive operations without needing to check for errors after each one, by passing the same error code object to all of them.

For cases where it is sufficient to check whether an error occurred, the error() method provides a convenient query:

ErrorCode err = new ErrorCode();
DoSomething (..., err);
if (err.error())
{
HandleError(err.details());
}

For cases requiring a more sophisticated approach, the value() and description() methods provide additional detail about the error code, message() provides access to the error message if there is one, and details() provides all available information in string form.

Thread safety:

  • Concurrent accesses to distinct objects: safe
  • Concurrent accesses to same object: unsafe, unless none of the accesses are to the set() or reset() methods

Classes

enum  Code
 Set of supported error codes. More...
 

Public Member Functions

 ErrorCode ()
 Create an ErrorCode in the default state - no error, empty message.
 
 ErrorCode (@NonNull Code err, @NonNull String msg)
 Create an ErrorCode with supplied error code and message. More...
 
String description ()
 Copy of current error description; this will be "No error" if no error condition has yet been flagged. More...
 
String details ()
 Copy of formatted error message, encoding both the error value and message string.
 
boolean error ()
 Does this object represent an error condition?
 
String message ()
 Copy of current error message; this will be an empty string if no message has yet been set.
 
void reset ()
 reset the error code to the default state (no error, empty message)
 
void set (@NonNull Code err, @NonNull String msg)
 set the error code to a new state More...
 
Code value ()
 Current error code ID; this will be NO_ERROR if no error condition has yet been flagged.
 

Static Public Attributes

static final String DEFAULT_MESSAGE
 Obtain the default error message.
 
static final Code DEFAULT_VALUE
 Default error ID value.
 

Constructor & Destructor Documentation

◆ ErrorCode()

ErrorCode ( @NonNull Code  err,
@NonNull String  msg 
)

Create an ErrorCode with supplied error code and message.

Parameters
errerror type ID; see Code for the list of supported values
msgerror message string

Member Function Documentation

◆ description()

String description ( )

Copy of current error description; this will be "No error" if no error condition has yet been flagged.

Note that this does not include the associated message; call details() instead if you wish for that to be included.

◆ set()

void set ( @NonNull Code  err,
@NonNull String  msg 
)

set the error code to a new state

Parameters
errerror type ID; see Code for the list of supported values
msgerror message string