KCal Library
#include <kresult.h>
Public Types | |
enum | ErrorType { NotAnError, Undefined, InvalidUrl, WrongParameter, ConnectionFailed, WriteError, ReadError, ParseError, WrongSchemaRevision } |
enum | Type { Ok, InProgress, Error } |
Public Member Functions | |
KResult () | |
KResult (const KResult &) | |
KResult (Type type) | |
KResult (ErrorType error, const QString &details=QString()) | |
~KResult () | |
KResult & | chain (const KResult &result) |
QString | chainedMessage () const |
KResult | chainedResult () const |
QString | details () const |
ErrorType | error () const |
QString | fullMessage () const |
bool | hasChainedResult () const |
bool | isError () const |
bool | isInProgress () const |
bool | isOk () const |
QString | message () const |
operator bool () const | |
void | setDetails (const QString &details) |
Detailed Description
This class represents the result of an operation.
It's meant to be used as return value of functions for returning status and especially error information.
There are three main types of result: Ok (operation successful completed), InProgress (operation still in progress) and Error (operation failed). InProgress is used by asynchronous operations. Functions which start an operation and return before the operation is finished should return the InProgress type result.
An error result can include information about the type of the error and a detailed error message. Translated error messages for the error types are available through the message() function. Additional detailed error messages can be set by the setDetails() function. A full error message including the type specific message and the details is available through fullMessage().
KResult objects can be chained using the chain function. If an operation executes a suboperation which indicates failure by returning a KResult object the operation can create a new KResult object and chain the suboperation's KResult object to it. The error information of chained results is available through the chainedMessage() function.
Examples:
A function returning ok:
KResult load() { return KResultOk(); }
Alternative notation:
KResult load() { return KResult::Ok; }
A function returning an error with a specific error message:
KResult load() { return KResultError( i18n("Details about error") ); }
A function returning an error of a sepcific type:
KResult load() { return KResultError( KResult::InvalidUrl ); }
Chaining errors:
KResult loadFile() { KResult result = mFile.load(); if ( !result.isError() ) { return KResultError( "File load error" ).chain( result ); } else { return result; } }
Checking for errors:
KResult load() { ... }
... if ( !load() ) error();
Member Enumeration Documentation
The different types of error conditions.
enum KCal::KResult::Type |
Constructor & Destructor Documentation
KResult::KResult | ( | ) |
Constructs a KResult object.
Private class that helps to provide binary compatibility between releases.
Default Type is Ok.
Definition at line 82 of file kresult.cpp.
KResult::KResult | ( | const KResult & | o | ) |
Copy constructor.
Definition at line 103 of file kresult.cpp.
|
explicit |
Creates a KResult object of the specified Type.
- Parameters
-
type is the result Type.
Definition at line 87 of file kresult.cpp.
Creates a KResult object of the specified ErrorType and an optional detailed error message.
- Parameters
-
error is the ErrorType. details is a QString containing optional details to add to the message corresponding to this error.
Definition at line 92 of file kresult.cpp.
KResult::~KResult | ( | ) |
Destroys the result.
Definition at line 97 of file kresult.cpp.
Member Function Documentation
Chains result objects.
This can be used to remember the cause of an error. The full error messages including the messages from chained objects can be accessed through chainedMessage().
- Parameters
-
result is another KResult to chain this one to.
Definition at line 184 of file kresult.cpp.
QString KResult::chainedMessage | ( | ) | const |
Returns an error message including full details of all chained messages.
This can constitute a backtrace of a error.
Definition at line 209 of file kresult.cpp.
KResult KResult::chainedResult | ( | ) | const |
Returns a chained KResult object.
Definition at line 195 of file kresult.cpp.
QString KResult::details | ( | ) | const |
Returns the detailed error message.
- See also
- setDetails().
Definition at line 179 of file kresult.cpp.
KResult::ErrorType KResult::error | ( | ) | const |
Returns the specific result ErrorType.
Definition at line 135 of file kresult.cpp.
QString KResult::fullMessage | ( | ) | const |
Returns the full error message.
This includes the type-specific message (see message()) and the detailed message (see details()).
Definition at line 200 of file kresult.cpp.
bool KResult::hasChainedResult | ( | ) | const |
Returns true if the KResult object has a chained KResult object; else returns false.
Definition at line 190 of file kresult.cpp.
bool KResult::isError | ( | ) | const |
Returns true if the result is Error.
Definition at line 130 of file kresult.cpp.
bool KResult::isInProgress | ( | ) | const |
Returns true if the result is InProgress.
Definition at line 125 of file kresult.cpp.
bool KResult::isOk | ( | ) | const |
Returns true if the result is Ok.
Definition at line 120 of file kresult.cpp.
QString KResult::message | ( | ) | const |
Returns a translated string describing the result corresponding to Type and ErrorType.
- See also
- fullMessage().
Definition at line 140 of file kresult.cpp.
KResult::operator bool | ( | ) | const |
Behave like a bool in the corresponding context.
Ok and InProgress are considered as success and return true, Error is considered as failure and returns false.
Definition at line 115 of file kresult.cpp.
void KResult::setDetails | ( | const QString & | details | ) |
Sets a detailed error message.
This error message should include all details needed to understand and recover from the error. This could be information like the URL which was tried, the file which could not be written or which parameter was missing.
- Parameters
-
details is a QString containing details to add to the message for this error.
- See also
- details().
Definition at line 174 of file kresult.cpp.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:30 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.