• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

KCal Library

KCal::KResult

KCal::KResult Class Reference

#include <kresult.h>

Inheritance diagram for KCal::KResult:

Inheritance graph
[legend]

List of all members.


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();

Definition at line 109 of file kresult.h.


Public Types

enum  ErrorType {
  NotAnError, Undefined, InvalidUrl, WrongParameter,
  ConnectionFailed, WriteError, ReadError, ParseError,
  WrongSchemaRevision
}
enum  Type { Ok, InProgress, Error }

Public Member Functions

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
 KResult (ErrorType error, const QString &details=QString())
 KResult (Type type)
 KResult (const KResult &)
 KResult ()
QString message () const
 operator bool () const
void setDetails (const QString &details)
 ~KResult ()

Member Enumeration Documentation

enum KCal::KResult::ErrorType

The different types of error conditions.

Enumerator:
NotAnError  Not an error.
Undefined  Undefined error.
InvalidUrl  Invalid URL.
WrongParameter  Invalid parameter.
ConnectionFailed  unable to establish a connection
WriteError  Write error.
ReadError  Read error.
ParseError  Parse error.
WrongSchemaRevision  Invalid schema revision.

Definition at line 124 of file kresult.h.

enum KCal::KResult::Type

The different types of results.

Enumerator:
Ok  Operation successfully completed.
InProgress  Operation still in-progress.
Error  Operation failed.

Definition at line 115 of file kresult.h.


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.

KResult::KResult ( Type  type  )  [explicit]

Creates a KResult object of the specified Type.

Parameters:
type is the result Type.

Definition at line 87 of file kresult.cpp.

KResult::KResult ( ErrorType  error,
const QString &  details = QString() 
) [explicit]

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

KResult & KResult::chain ( const KResult &  result  ) 

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:
  • kresult.h
  • kresult.cpp

KCal Library

Skip menu "KCal Library"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal