Qx v0.5.7
Qt Extensions Library
Loading...
Searching...
No Matches
Qx::AbstractError< EName, ECode > Class Template Reference

The AbstractError template class completes the Error interface and acts as the base class from which specific error types are implemented. More...

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

Collaboration diagram for Qx::AbstractError< EName, ECode >:
[legend]

Public Member Functions

 operator bool () const
 
bool operator!= (const AbstractError &other) const =default
 
bool operator== (const AbstractError &other) const =default
 

Static Public Attributes

static constexpr quint16 TYPE_CODE = ECode
 
static constexpr QLatin1StringView TYPE_NAME {EName.value}
 

Friends

class Error
 

Additional Inherited Members

- Protected Member Functions inherited from Qx::IError
 IError ()=default
 
virtual QString deriveCaption () const
 
virtual QString deriveDetails () const
 
virtual QString derivePrimary () const
 
virtual QString deriveSecondary () const
 
virtual Severity deriveSeverity () const
 
virtual quint32 deriveValue () const
 
bool operator!= (const IError &other) const =default
 
bool operator== (const IError &other) const =default
 

Detailed Description

template<StringLiteral EName, quint16 ECode>
class Qx::AbstractError< EName, ECode >
Subclassing

To create a concrete error type, inherit from AbstractError, instantiate it with the new error types name and type code, and then override the derive...() methods defined by the IError interface as required. Generally you should at least override deriveValue() and derivePrimary(). Or, for the most common case one can use QX_ERROR_TYPE().

Note
Type codes 0-999 are reserved by Qx.
class MyError final : public Qx::AbstractError<"MyError", 1015>
{
private:
quint16 mErrorValue;
QString mPrimaryCause;
public:
MyError() :
mErrorValue(1),
mPrimaryCause("A bad thing happened.")
{}
private:
void deriveValue() { return mErrorValue; }
void derivePrimary() { return mPrimaryCause; }
//...
}

Using the string form of the class as the type name (with the potential enclosing scope) is preferred, but not strictly required. It's recommended to mark the class as final since further derivations would share its error type code, spoiling its uniqueness.

To create an intermediate error type from which other error types are meant to share an implementation, simply derive from AbstractError without instantiating it. Then, derive your concrete error types (or other intermediates) from that class as you would AbstractError directly.

template<StringLiteral EName, quint16 ECode>
class MyErrorTemplate : public AbstractError<EName, ECode>
{
protected:
MyErrorTemplate() {}
private:
//...
}

The implementation of Qx::IoOpReport is a good example of how to extend AbstractError.

Member Function Documentation

◆ operator bool()

template<StringLiteral EName, quint16 ECode>
Qx::AbstractError< EName, ECode >::operator bool ( ) const
inline

A convenience operator to check if the error is valid. Produces true if the value of the error is greater than 0; otherwise, produces false.

◆ operator!=()

template<StringLiteral EName, quint16 ECode>
bool Qx::AbstractError< EName, ECode >::operator!= ( const AbstractError< EName, ECode > & other) const
default

Returns true if this error is not the same as other; otherwise, returns false.

◆ operator==()

template<StringLiteral EName, quint16 ECode>
bool Qx::AbstractError< EName, ECode >::operator== ( const AbstractError< EName, ECode > & other) const
default

Returns true if this error is the same as other; otherwise, returns false.

See also
equivalent().

Member Data Documentation

◆ TYPE_CODE

template<StringLiteral EName, quint16 ECode>
quint16 Qx::AbstractError< EName, ECode >::TYPE_CODE = ECode
staticconstexpr

The type code of the specific error type. Dictated by ECode.

◆ TYPE_NAME

template<StringLiteral EName, quint16 ECode>
quint16 Qx::AbstractError< EName, ECode >::TYPE_NAME {EName.value}
staticconstexpr

The type name of the specific error type. Dictated by EName.


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