Next: , Previous: , Up: handlers init   [Contents][Index]


5.2.2 Initialising error handlers with generic macros

All the following definitions are accessible from the header file ccexceptions.h.

Preprocessor Macro: void cce_init_handler (cce_error_handler_t * H, cce_error_handler_fun_t * handler_function, void * RESOURCE_POINTER)

Initialise the error handler referenced by H with the given handler function and resource pointer; the argument RESOURCE_POINTER can be NULL.

Upon exiting the associated location context: the handler might finalise the resource referenced by RESOURCE_POINTER, but it can also perform some unrelated operations.

Preprocessor Macro: void cce_init_handler (cce_error_handler_t * H, cce_error_handler_fun_t * handler_function, void * RESOURCE_POINTER, cce_resource_destructor_fun_t * RESOURCE_DESTRUCTOR)

Initialise the error handler referenced by H with the given handler function, resource pointer and resource destructor; the arguments RESOURCE_POINTER and RESOURCE_DESTRUCTOR can be NULL.

Upon exiting the associated location context: the handler might finalise the resource referenced by RESOURCE_POINTER using the destructor function referenced by RESOURCE_DESTRUCTOR, but it can also perform some unrelated operations.

As example of initialising a error handler:

void
error_handler (cce_condition_t const * C, cce_error_handler_t const * P_H)
{
  free(cce_handler_resource_pointer(P_H));
}

void
main (void)
{
  cce_location_t          L[1];
  cce_error_handler_t     P_H[1];

  if (cce_location(L)) {
    cce_run_catch_handlers_final(L);
  } else {
    void *  P = cce_sys_malloc(L, 4096);
    cce_init_handler(P_H, error_handler, cce_resource_pointer(P));
    cce_register_handler(L, P_H);

    /* Do something with "P". */
    cce_run_body_handlers(L);
  }
}

As example of initialising a error handler using a destructor function:

void
error_handler (cce_condition_t const * C, cce_error_handler_t const * P_H)
{
  cce_resource_destructor_fun_t * release;

  release = cce_handler_resource_destructor(P_H);
  release(cce_handler_resource_pointer(P_H));
}

void
main (void)
{
  cce_location_t          L[1];
  cce_error_handler_t     P_H[1];

  if (cce_location(L)) {
    cce_run_catch_handlers_final(L);
  } else {
    void *  P = cce_sys_malloc(L, 4096);
    cce_init_handler(P_H, error_handler, cce_resource_pointer(P), free);
    cce_register_handler(L, P_H);

    /* Do something with "P". */
    cce_run_body_handlers(L);
  }
}

As example of initialising a error handler using a destructor function and the built–in handler function:

void
main (void)
{
  cce_location_t          L[1];
  cce_error_handler_t     P_H[1];

  if (cce_location(L)) {
    cce_run_catch_handlers_final(L);
  } else {
    void *  P = cce_sys_malloc(L, 4096);
    cce_init_handler(P_H, cce_default_error_handler_function,
                     cce_resource_pointer(P), free);
    cce_register_handler(L, P_H);

    /* Do something with "P". */
    cce_run_body_handlers(L);
  }
}

Next: , Previous: , Up: handlers init   [Contents][Index]

This document describes version 0.9.0-devel.3 of CCExceptions.