This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

difference between VERIFY_SUCCESS() and APP_ERROR_CHECK()

Hello I am using the NRF52832 in ESB mode. I use both VERIFY_SUCCESS() and APP_ERROR_CHECK() within my code in various places but when am I supposed to use versus the other. For example, I use:

err_code = esb_init();

VERIFY_SUCCESS(err_code);

then, somewhere else I use...

err_code = nrf_esb_disable();

APP_ERROR_CHECK(err_code);

Parents
  • Hi,

    I have included the relevant implementations of the macros from SDK14 to help you see the difference between them:

    /**@brief Macro for verifying statement to be false. It will cause the exterior function to return
     *        err_code if the statement is not false.
     *
     * @param[in]   statement   Statement to test.
     * @param[in]   err_code    Error value to return if test was invalid.
     *
     * @retval      nothing, but will cause the exterior function to return @p err_code if @p statement
     *              is true.
     */
    #define VERIFY_FALSE(statement, err_code)   \
    do                                          \
    {                                           \
        if ((statement))                        \
        {                                       \
            return err_code;                    \
        }                                       \
    } while (0)
    
    /**@brief Macro for verifying that a function returned NRF_SUCCESS. It will cause the exterior
     *        function to return err_code if the err_code is not @ref NRF_SUCCESS.
     *
     * @param[in] err_code The error code to check.
     */
    #ifdef DISABLE_PARAM_CHECK
    #define VERIFY_SUCCESS()
    #else
    #define VERIFY_SUCCESS(err_code) VERIFY_TRUE((err_code) == NRF_SUCCESS, (err_code))
    #endif /* DISABLE_PARAM_CHECK */
    
    /**@brief Macro for calling error handler function if supplied error code any other than NRF_SUCCESS.
     *
     * @param[in] ERR_CODE Error code supplied to the error handler.
     */
    #define APP_ERROR_CHECK(ERR_CODE)                           \
        do                                                      \
        {                                                       \
            const uint32_t LOCAL_ERR_CODE = (ERR_CODE);         \
            if (LOCAL_ERR_CODE != NRF_SUCCESS)                  \
            {                                                   \
                APP_ERROR_HANDLER(LOCAL_ERR_CODE);              \
            }                                                   \
        } while (0)
    

    As you can see from the above snippet, VERIFY_SUCCESS() macro will verify that err_code is equal to NRF_SUCCESS. If this statement is not true, it will return the error code. This is usefull if you want a function call to stop executing and returning the error code if an error have occurred.

    APP_ERROR_CHECK() will call the error handler if the given err_code is not NRF_SUCCESS.

    Best regards,

    Jørgen

Reply
  • Hi,

    I have included the relevant implementations of the macros from SDK14 to help you see the difference between them:

    /**@brief Macro for verifying statement to be false. It will cause the exterior function to return
     *        err_code if the statement is not false.
     *
     * @param[in]   statement   Statement to test.
     * @param[in]   err_code    Error value to return if test was invalid.
     *
     * @retval      nothing, but will cause the exterior function to return @p err_code if @p statement
     *              is true.
     */
    #define VERIFY_FALSE(statement, err_code)   \
    do                                          \
    {                                           \
        if ((statement))                        \
        {                                       \
            return err_code;                    \
        }                                       \
    } while (0)
    
    /**@brief Macro for verifying that a function returned NRF_SUCCESS. It will cause the exterior
     *        function to return err_code if the err_code is not @ref NRF_SUCCESS.
     *
     * @param[in] err_code The error code to check.
     */
    #ifdef DISABLE_PARAM_CHECK
    #define VERIFY_SUCCESS()
    #else
    #define VERIFY_SUCCESS(err_code) VERIFY_TRUE((err_code) == NRF_SUCCESS, (err_code))
    #endif /* DISABLE_PARAM_CHECK */
    
    /**@brief Macro for calling error handler function if supplied error code any other than NRF_SUCCESS.
     *
     * @param[in] ERR_CODE Error code supplied to the error handler.
     */
    #define APP_ERROR_CHECK(ERR_CODE)                           \
        do                                                      \
        {                                                       \
            const uint32_t LOCAL_ERR_CODE = (ERR_CODE);         \
            if (LOCAL_ERR_CODE != NRF_SUCCESS)                  \
            {                                                   \
                APP_ERROR_HANDLER(LOCAL_ERR_CODE);              \
            }                                                   \
        } while (0)
    

    As you can see from the above snippet, VERIFY_SUCCESS() macro will verify that err_code is equal to NRF_SUCCESS. If this statement is not true, it will return the error code. This is usefull if you want a function call to stop executing and returning the error code if an error have occurred.

    APP_ERROR_CHECK() will call the error handler if the given err_code is not NRF_SUCCESS.

    Best regards,

    Jørgen

Children
Related