Error handling is an important and complex problem in any software system. Within our framework, error handling is ubiquitous and extremely cumbersome.
In the interfaces we exposed to users, we try to make things as simple as possible, but users still inevitably need to know some error messages.
C++ exceptions are not used in our framework. When you compile your own code, it is best to add -fno-exceptions flag to reduce the code size.
According to the common practice in the industry, we ignore the possibility of the failure of new operation, and avoid using new to allocate large blocks of memory internally. And there are error checks in memory allocation in C style.
From the previous examples, you can see that all task and series are generated from two factory classes, WFTaskFactory or Workflow.
These factory classes, as well as more factory class interfaces that we may encounter in the future, ensure success. In other words, they never return NULL. And you do not need to check the return value.
To achieve this goal, even when the URL is illegal, the factory still generates the task normally. And you will get the error in the callback of the task.
In the previous examples, you often see such codes in the callback:
void callback(WFXxxTask *task)
{
int state = task->get_state();
int error = task->get_error();
...
}
in which, the state indicates the end state of a task. WFTask.h contains all possible states:
enum
{
WFT_STATE_UNDEFINED = -1,
WFT_STATE_SUCCESS = CS_STATE_SUCCESS,
WFT_STATE_TOREPLY = CS_STATE_TOREPLY, /* for server task only */
WFT_STATE_NOREPLY = CS_STATE_TOREPLY + 1, /* for server task only */
WFT_STATE_SYS_ERROR = CS_STATE_ERROR,
WFT_STATE_SSL_ERROR = 65,
WFT_STATE_DNS_ERROR = 66, /* for client task only */
WFT_STATE_TASK_ERROR = 67,
WFT_STATE_ABORTED = CS_STATE_STOPPED /* main process terminated */
};
In addition to the error handling of the task itself, you also need to check the errors of the message interfaces of various protocols. Generally, these interfaces indicate errors by returning false, and show the error reasons in the errno.
In addition, you may encounter more complicated error messages when you use some complex operations. You will learn them in detailed documents.
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Опубликовать ( 0 )