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.
{
private:
quint16 mErrorValue;
public:
MyError() :
mErrorValue(1),
mPrimaryCause("A bad thing happened.")
{}
private:
}
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.