Error Macros
[Error Manager]


ERROR MANAGEMENT MACROS

Helper Macros to deal with the error management. Sample usage:
                alp_status_t foo()
                {
                        ALP_ERROR_MANAGE                // Enable error management

                        ALP_FAIL(foo2())                // status_t foo2();

                ALP_ON_ERROR                            // Manage error conditions / cleanup
                        return ALP_ERROR;               // Return actual error value
                }


#define ALP_ERROR   _err_
 Contains the actual error value.
#define ALP_ERROR_MANAGE   alp_status_t ALP_ERROR = ALP_STATUS_OK;
 Needed at the beginning of the function for the following macros to work properly.
#define ALP_FAIL(statement)
 Execute a statement and check success. Jump to ALP_ON_ERROR in case of failure.
#define ALP_FAIL_ERROR(statement, error)
 Execute a statement and check success. Jump to ALP_ON_ERROR in case of failure.
#define ALP_FAIL_ERROR_LABEL(statement, error, label)
 Execute a statement and check success. Jump to ALP_ON_ERROR in case of failure.
#define ALP_FAIL_LABEL(statement, label)
 Execute a statement and check success. Jump to ALP_ON_ERROR in case of failure.
#define ALP_FAIL_MALLOC(var, size, error)
 Allocate memory and check success. Jump to ALP_ON_ERROR in case of failure.
#define ALP_FAIL_NULL(var, statement, error)
 Assigns the value of statement to the variable var. Jump to ALP_ON_ERROR if expression evaluates to NULL.
#define ALP_FAIL_NULL_LABEL(var, statement, error, label)
 Assigns the value of statement to the variable var. Jump to ALP_ON_ERROR if expression evaluates to NULL.
#define ALP_ON_ERROR   _on_error_
 Functions can jump to this label if they are performing their own error handling outside of the error macros.
#define ALP_ON_ERROR_LABEL   ALP_ON_ERROR:
 ALP_FAIL and ALP_FAIL_ERROR and ALP_FAIL_MALLOC macros will jump to this bloc in case of an error.

ERROR CONSTRUCTION MACROS

Helper Macros to deal with error construction.

#define ALP_ERROR_DECLARE(class, error)   ((alp_status_t)((alp_status_t)(class) | (alp_status_t)(error) << 16))
 Define an error.
#define ALP_ERROR_SET_INFO(error, info)   (alp_status_t)(((alp_status_t)(error))| ((((alp_status_t)(info)) >> 16) & 0x0000FFFF))
 Set the error info part.


Define Documentation

#define ALP_ERROR   _err_
 

Contains the actual error value.

#define ALP_ERROR_DECLARE class,
error   )     ((alp_status_t)((alp_status_t)(class) | (alp_status_t)(error) << 16))
 

Define an error.

#define ALP_ERROR_MANAGE   alp_status_t ALP_ERROR = ALP_STATUS_OK;
 

Needed at the beginning of the function for the following macros to work properly.

#define ALP_ERROR_SET_INFO error,
info   )     (alp_status_t)(((alp_status_t)(error))| ((((alp_status_t)(info)) >> 16) & 0x0000FFFF))
 

Set the error info part.

See also:
ALP_STATUS_VALUE

ALP_STATUS_INFO

#define ALP_FAIL statement   ) 
 

Value:

Execute a statement and check success. Jump to ALP_ON_ERROR in case of failure.

Parameters:
[in] statement the statement to execute. The call must return a status_t.

#define ALP_FAIL_ERROR statement,
error   ) 
 

Value:

{ALP_ERROR = statement;\
                                                                                                                if(ALP_STATUS_VALUE(ALP_ERROR) != ALP_STATUS_OK)\
                                                                                                                {\
                                                                                                                        ALP_ERROR = error;\
                                                                                                                        goto ALP_ON_ERROR;\
                                                                                                                }}
Execute a statement and check success. Jump to ALP_ON_ERROR in case of failure.

Parameters:
[in] statement the statement to execute. The call must return a status_t.
[in] error explicitely assign this error code to ALP_ERROR before jumping to ALP_ON_ERROR label.

#define ALP_FAIL_ERROR_LABEL statement,
error,
label   ) 
 

Value:

{ALP_ERROR = statement;\
                                                                                                                if(ALP_STATUS_VALUE(ALP_ERROR) != ALP_STATUS_OK)\
                                                                                                                {\
                                                                                                                        ALP_ERROR = error;\
                                                                                                                        goto label;\
                                                                                                                }}
Execute a statement and check success. Jump to ALP_ON_ERROR in case of failure.

Parameters:
[in] statement the statement to execute. The call must return a status_t.
[in] error explicitely assign this error code to ALP_ERROR before jumping to ALP_ON_ERROR label.
[in] label jump to this label rather than the standard ALP_ON_ERROR one.

#define ALP_FAIL_LABEL statement,
label   ) 
 

Value:

{ALP_ERROR = statement;\
                                                                                                                if(ALP_STATUS_VALUE(ALP_ERROR) != ALP_STATUS_OK)\
                                                                                                                        goto label;}
Execute a statement and check success. Jump to ALP_ON_ERROR in case of failure.

Parameters:
[in] statement the statement to execute. The call must return a status_t.
[in] label jump to this label rather than the standard ALP_ON_ERROR one.

#define ALP_FAIL_MALLOC var,
size,
error   ) 
 

Value:

{(var) = malloc((size));\
                                                                                                                if((var) == NULL)\
                                                                                                                {\
                                                                                                                        ALP_ERROR = error;\
                                                                                                                        goto ALP_ON_ERROR;\
                                                                                                                }}
Allocate memory and check success. Jump to ALP_ON_ERROR in case of failure.

Parameters:
[in] var the variable to allocate
[in] size allocation size
[in] error error code assigned to ALP_ERROR

#define ALP_FAIL_NULL var,
statement,
error   ) 
 

Value:

{(var) = statement; \
                                                                if((var) == NULL) \
                                                                                                                {\
                                                                                                                        ALP_ERROR = error; \
                                                                                                                        goto ALP_ON_ERROR; \
                                                                                                                }}
Assigns the value of statement to the variable var. Jump to ALP_ON_ERROR if expression evaluates to NULL.

Parameters:
[out] var the variable to hold the value of statement.
[in] statement the statement to execute. The call must return a valid pointer of 0.
[in] error error code assigned to ALP_ERROR

#define ALP_FAIL_NULL_LABEL var,
statement,
error,
label   ) 
 

Value:

{(var) = statement; \
                                                                if((var) == NULL) \
                                                                                                                {\
                                                                                                                        ALP_ERROR = error; \
                                                                                                                        goto label; \
                                                                                                                }}
Assigns the value of statement to the variable var. Jump to ALP_ON_ERROR if expression evaluates to NULL.

Parameters:
[out] var the variable to hold the value of statement.
[in] statement the statement to execute. The call must return a valid pointer of 0.
[in] error error code assigned to ALP_ERROR
[in] label jump to this label rather than the standard ALP_ON_ERROR one.

#define ALP_ON_ERROR   _on_error_
 

Functions can jump to this label if they are performing their own error handling outside of the error macros.

#define ALP_ON_ERROR_LABEL   ALP_ON_ERROR:
 

ALP_FAIL and ALP_FAIL_ERROR and ALP_FAIL_MALLOC macros will jump to this bloc in case of an error.


Generated on Wed Jul 30 07:06:42 2008 by Doxygen 1.4.6 for ALP SDK + Hiker Documentation

Copyright © 1999-2008 ACCESS CO., LTD. All rights reserved.