QEverCloud
Unofficial Evernote Cloud API for Qt
Public Member Functions | Public Attributes | List of all members
qevercloud::EverCloudExceptionData Class Reference

EverCloudException counterpart for asynchronous API. More...

Inherits QObject.

Inherited by qevercloud::EvernoteExceptionData, and qevercloud::ThriftExceptionData.

Public Member Functions

 EverCloudExceptionData (QString err)
 
virtual void throwException () const
 If you want to throw an exception that corresponds to a recrived EverCloudExceptionData descendant than call this function. More...
 

Public Attributes

QString errorMessage
 Contains an error message. More...
 

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<EDAMSystemExceptionRateLimitReachedData> errorRateLimitReached = error.objectCast<EDAMSystemExceptionRateLimitReachedData>();
QSharedPointer<EDAMSystemExceptionAuthExpiredData> errorAuthExpired = error.objectCast<EDAMSystemExceptionAuthExpiredData>();
QSharedPointer<EDAMNotFoundExceptionData> errorNotFound = error.objectCast<EDAMNotFoundExceptionData>();
QSharedPointer<EDAMUserExceptionData> errorUser = error.objectCast<EDAMUserExceptionData>();
QSharedPointer<EDAMSystemExceptionData> errorSystem = error.objectCast<EDAMSystemExceptionData>();
if(!errorAuthExpired.isNull()) {
qDebug() << "authentication token is expired!" << endl;
if(!errorRateLimitReached.isNull()) {
qDebug() << "Evernote API rate limit is reached! Wait at least for " << errorRateLimitReached.rateLimitDuration << " seconds." <<endl;
} else 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
}
});

Note the handling of the EDAMSystemExceptionRateLimitReached and EDAMSystemExceptionAuthExpired cases. They should be handled for any Evernote API function call in a special way.

Member Function Documentation

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

Member Data Documentation

QString qevercloud::EverCloudExceptionData::errorMessage

Contains an error message.

It's the std::exception::what() counterpart.