QEverCloud  6.1.0
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...

#include <EverCloudException.h>

Inheritance diagram for qevercloud::EverCloudExceptionData:
qevercloud::EvernoteExceptionData qevercloud::NetworkExceptionData qevercloud::ThriftExceptionData qevercloud::EDAMInvalidContactsExceptionData 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, EverCloudExceptionData error)
{
if (!error.isNull())
{
auto errorNotFound =
std::dynamic_pointer_cast<EDAMNotFoundExceptionData>(
error);
auto errorUser =
std::dynamic_pointer_cast<EDAMUserExceptionData>(
error);
auto errorSystem =
std::dynamic_pointer_cast<EDAMSystemExceptionData>(
error);
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

◆ EverCloudExceptionData()

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

Member Function Documentation

◆ throwException()

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

Member Data Documentation

◆ errorMessage

QString qevercloud::EverCloudExceptionData::errorMessage

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

qevercloud::AsyncResult::finished
void finished(QVariant result, EverCloudExceptionDataPtr error, IRequestContextPtr ctx)
Emitted upon asynchronous call completition.
qevercloud::EverCloudExceptionData::EverCloudExceptionData
EverCloudExceptionData(QString error)