QEverCloud  3.0.0
Unofficial Evernote Cloud API for Qt
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Public Attributes | List of all members
qevercloud::EverCloudExceptionData Class Reference

EverCloudException counterpart for asynchronous API. More...

#include <EverCloudException.h>

Inheritance diagram for qevercloud::EverCloudExceptionData:
qevercloud::EvernoteExceptionData qevercloud::ThriftExceptionData qevercloud::EDAMNotFoundExceptionData qevercloud::EDAMSystemExceptionData qevercloud::EDAMUserExceptionData qevercloud::EDAMSystemExceptionAuthExpiredData qevercloud::EDAMSystemExceptionRateLimitReachedData

Public Member Functions

 EverCloudExceptionData (QString error)
 
virtual void throwException () const
 

Public Attributes

QString errorMessage
 

Detailed Description

EverCloudException counterpart for asynchronous API.

Asynchronous functions cannot throw exceptions so descendants of EverCloudExceptionData are retunded instead in case of an error. Every exception class has its own counterpart. The EverCloudExceptionData descendants hierarchy is a copy of the EverCloudException descendants hierarchy.

The main reason not to use exception classes directly is that dynamic_cast does not work across module (exe, dll, etc) boundaries in general, while qobject_cast do work as expected. That's why I decided to inherit my error classes from QObject.

In general error checking in asynchronous API look like this:

NoteStore* ns;
...
QObject::connect(ns->getNotebook(notebookGuid), &AsyncResult::finished, [](QVariant result, QSharedPointer<EverCloudExceptionData> error) {
if(!error.isNull()) {
QSharedPointer<EDAMNotFoundExceptionData> errorNotFound = error.objectCast<EDAMNotFoundExceptionData>();
QSharedPointer<EDAMUserExceptionData> errorUser = error.objectCast<EDAMUserExceptionData>();
QSharedPointer<EDAMSystemExceptionData> errorSystem = error.objectCast<EDAMSystemExceptionData>();
if(!errorNotFound.isNull()) {
qDebug() << "notebook not found" << errorNotFound.identifier << errorNotFound.key;
} else if(!errorUser.isNull()) {
qDebug() << errorUser.errorMessage;
} else if(!errorSystem.isNull()) {
if(errorSystem.errorCode == EDAMErrorCode::RATE_LIMIT_REACHED) {
qDebug() << "Evernote API rate limits are reached";
} else if(errorSystem.errorCode == EDAMErrorCode::AUTH_EXPIRED) {
qDebug() << "Authorization token is inspired";
} else {
// some other Evernote trouble
qDebug() << errorSystem.errorMessage;
}
} else {
// some unexpected error
qDebug() << error.errorMessage;
}
} else {
// success
}
});

Constructor & Destructor Documentation

qevercloud::EverCloudExceptionData::EverCloudExceptionData ( QString  error)
explicit

Member Function Documentation

virtual void qevercloud::EverCloudExceptionData::throwException ( ) const
virtual

Member Data Documentation

QString qevercloud::EverCloudExceptionData::errorMessage

Contains an error message. It's the std::exception::what() counterpart.