1tutorial_error_page(3)     Library Functions Manual     tutorial_error_page(3)
2
3
4

NAME

6       tutorial_error_page - Error Tutorial
7

Introduction

9       The Eina error module provides a way to manage errors in a simple but
10       powerful way in libraries and modules. It is also used in Eina itself.
11       Similar to libC's errno and strerror() facilities, this is extensible
12       and recommended for other libraries and applications.
13

Registering messages

15       The error module can provide a system that mimic the errno system of
16       the C standard library. It consists in 2 parts:
17
18       · a way of registering new messages with eina_error_msg_register() and
19         eina_error_msg_get(),
20       · a way of setting / getting last error message with eina_error_set() /
21         eina_error_get().
22       So one has to fisrt register all the error messages that a program or a
23       lib should manage. Then, when an error can occur, use eina_error_set(),
24       and when errors are managed, use eina_error_get(). If eina_error_set()
25       is used to set an error, do not forget to call before eina_error_set0),
26       to remove previous set errors.
27       Here is an example of use:
28        #include <stdlib.h>
29        #include <stdio.h>
30
31        #include <eina_error.h>
32
33        Eina_Error MY_ERROR_NEGATIVE;
34        Eina_Error MY_ERROR_NULL;
35
36        voi *data_new()
37        {
38           eina_error_set(0);
39
40           eina_error_set(MY_ERROR_NULL);
41           return NULL;
42        }
43
44        int test(int n)
45        {
46           eina_error_set(0);
47
48           if (n < 0)
49           {
50              eina_error_set(MY_ERROR_NEGATIVE);
51              return 0;
52           }
53
54           return 1;
55        }
56
57        int main(void)
58        {
59           void *data;
60
61           if (!eina_init())
62           {
63              printf ('Error during the initialization of eina_error module0);
64              return EXIT_FAILURE;
65           }
66
67           MY_ERROR_NEGATIVE = eina_error_msg_register('Negative number');
68           MY_ERROR_NULL = eina_error_msg_register('NULL pointer');
69
70           data = data_new();
71           if (!data)
72           {
73              Eina_Error err;
74
75              err = eina_error_get();
76              if (err)
77                 printf('Error during memory allocation: %s0,
78                        eina_error_msg_get(err));
79           }
80
81           if (!test(0))
82           {
83              Eina_Error err;
84
85              err = eina_error_get();
86              if (err)
87                 printf('Error during test function: %s0,
88                        eina_error_msg_get(err));
89           }
90
91           if (!test(-1))
92           {
93              Eina_Error err;
94
95              err = eina_error_get();
96              if (err)
97                 printf('Error during test function: %s0,
98                        eina_error_msg_get(err));
99           }
100
101           eina_shutdown();
102
103           return EXIT_SUCCESS;
104        }
105       Of course, instead of printf(), eina_log_print() can be used to have
106       beautiful error messages.
107
108
109
110Eina                              2 Jul 2010            tutorial_error_page(3)
Impressum