Qx v0.5.7
Qt Extensions Library
Loading...
Searching...
No Matches
Qx::JsonError Class Referencefinal

The JsonError class is used to report errors related to JSON manipulation.

#include <qx/core/qx-json.h>

Collaboration diagram for Qx::JsonError:
[legend]

Public Types

enum  Form {
  NoError = 0 ,
  MissingKey ,
  TypeMismatch ,
  EmptyDoc ,
  InvalidValue ,
  MissingFile ,
  InaccessibleFile ,
  FileReadError
}
 

Public Member Functions

 JsonError ()
 
 JsonError (const QString &a, Form f)
 
QString action () const
 
QList< QxJson::ContextNodecontext () const
 
Form form () const
 
bool isValid () const
 
JsonErrorwithContext (const QxJson::ContextNode &node)
 
- Public Member Functions inherited from Qx::AbstractError<"Qx::JsonError", 5 >
 operator bool () const
 
bool operator!= (const AbstractError &other) const=default
 
bool operator== (const AbstractError &other) const=default
 

Additional Inherited Members

- Static Public Attributes inherited from Qx::AbstractError<"Qx::JsonError", 5 >
static constexpr quint16 TYPE_CODE
 
static constexpr QLatin1StringView TYPE_NAME
 
- Protected Member Functions inherited from Qx::IError
 IError ()=default
 
virtual QString deriveCaption () const
 
virtual Severity deriveSeverity () const
 
bool operator!= (const IError &other) const =default
 
bool operator== (const IError &other) const =default
 

Member Enumeration Documentation

◆ Form

This enum represents form of JSON error.

Enumerator
NoError 

No error occurred.

MissingKey 

An expected key was missing.

Constructor & Destructor Documentation

◆ JsonError() [1/2]

Qx::JsonError::JsonError ( )

Creates an invalid JsonError.

◆ JsonError() [2/2]

Qx::JsonError::JsonError ( const QString & a,
Form f )

Creates a JSON error with the action and error form f.

Member Function Documentation

◆ action()

QString Qx::JsonError::action ( ) const

A message noting the attempted action that failed.

◆ context()

QList< QxJson::ContextNode > Qx::JsonError::context ( ) const

Provides the full context in which the error occurred.

◆ form()

JsonError::Form Qx::JsonError::form ( ) const

The form of error that occurred.

◆ isValid()

bool Qx::JsonError::isValid ( ) const

Returns true if an error occurred; otherwise, returns false.

◆ withContext()

JsonError & Qx::JsonError::withContext ( const QxJson::ContextNode & node)

Prepends the context node node to the error's context and returns a reference to the updated error object. This function is a no-op if the error is not valid.

Generally this function is of no use in user code, but can be utilized when providing complex custom parsing for user types via QX_JSON_MEMBER_OVERRIDE or Converter specializations.

Typically, this function is used in a chain of return calls in order to pass the context of where an error occurred up the call stack. For example, one might return information about a JSON array related error like so:

// Somehow populate array...
for(int i = 0; i < ja.size(); ++i)
{
// Parse element
if(Qx::JsonError je = parseMyElement(ja[i]); je.isValid())
return je.withContext(QxJson::Array()).withContext(QxJson::ArrayElement(i));
}

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