\hypertarget{eina_error_01_8c-example}{}\doxysection{eina\+\_\+error\+\_\+01.\+c}
Of course, instead of printf(), \mbox{\hyperlink{group__Eina__Log__Group_ga6d455dd27e2148919e225aec3a159c0c}{eina\+\_\+log\+\_\+print()}} can be used to have beautiful error messages.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{comment}{//Compile with:}}
\DoxyCodeLine{\textcolor{comment}{//gcc -\/g eina\_error\_01.c -\/o eina\_error\_01 `pkg-\/config -\/-\/cflags -\/-\/libs eina`}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <stdlib.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <stdio.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <eina\_main.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <eina\_error.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\mbox{\hyperlink{group__Eina__Error__Group_ga95b3cbb33e987e7d92a81ea785001686}{Eina\_Error}} MY\_ERROR\_NEGATIVE;}
\DoxyCodeLine{\mbox{\hyperlink{group__Eina__Error__Group_ga95b3cbb33e987e7d92a81ea785001686}{Eina\_Error}} MY\_ERROR\_NULL;}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{void} *data\_new()}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__Error__Group_ga7e6b1448d7730fc821736bda8964d739}{eina\_error\_set}}(0);}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__Error__Group_ga7e6b1448d7730fc821736bda8964d739}{eina\_error\_set}}(MY\_ERROR\_NULL);}
\DoxyCodeLine{   \textcolor{keywordflow}{return} NULL;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int} test(\textcolor{keywordtype}{int} n)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__Error__Group_ga7e6b1448d7730fc821736bda8964d739}{eina\_error\_set}}(0);}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (n < 0)}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        \mbox{\hyperlink{group__Eina__Error__Group_ga7e6b1448d7730fc821736bda8964d739}{eina\_error\_set}}(MY\_ERROR\_NEGATIVE);}
\DoxyCodeLine{        \textcolor{keywordflow}{return} 0;}
\DoxyCodeLine{     \}}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} 1;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int} main(\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keywordtype}{void} *data;}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (!\mbox{\hyperlink{group__Eina__Main__Group_ga81b8137665b8a4d2cb38ca50017d4c74}{eina\_init}}())}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        printf (\textcolor{stringliteral}{"{}Error during the initialization of eina\_error module\(\backslash\)n"{}});}
\DoxyCodeLine{        \textcolor{keywordflow}{return} EXIT\_FAILURE;}
\DoxyCodeLine{     \}}
\DoxyCodeLine{}
\DoxyCodeLine{   MY\_ERROR\_NEGATIVE = \mbox{\hyperlink{group__Eina__Error__Group_ga4a2be38f81f21dab8472ffb6bfd49ab7}{eina\_error\_msg\_static\_register}}(\textcolor{stringliteral}{"{}Negative number"{}});}
\DoxyCodeLine{   MY\_ERROR\_NULL = \mbox{\hyperlink{group__Eina__Error__Group_ga4a2be38f81f21dab8472ffb6bfd49ab7}{eina\_error\_msg\_static\_register}}(\textcolor{stringliteral}{"{}NULL pointer"{}});}
\DoxyCodeLine{}
\DoxyCodeLine{   data = data\_new();}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (!data)}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        \mbox{\hyperlink{group__Eina__Error__Group_ga95b3cbb33e987e7d92a81ea785001686}{Eina\_Error}} err;}
\DoxyCodeLine{}
\DoxyCodeLine{        err = \mbox{\hyperlink{group__Eina__Error__Group_gaf1afffc7dc1e11101f47c5d14d9c5347}{eina\_error\_get}}();}
\DoxyCodeLine{        \textcolor{keywordflow}{if} (err)}
\DoxyCodeLine{           printf(\textcolor{stringliteral}{"{}Error during memory allocation: \%s\(\backslash\)n"{}},}
\DoxyCodeLine{                  \mbox{\hyperlink{group__Eina__Error__Group_gac420af42486bcbb879c4be67eacc6c2a}{eina\_error\_msg\_get}}(err));}
\DoxyCodeLine{     \}}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (!test(0))}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        \mbox{\hyperlink{group__Eina__Error__Group_ga95b3cbb33e987e7d92a81ea785001686}{Eina\_Error}} err;}
\DoxyCodeLine{}
\DoxyCodeLine{        err = \mbox{\hyperlink{group__Eina__Error__Group_gaf1afffc7dc1e11101f47c5d14d9c5347}{eina\_error\_get}}();}
\DoxyCodeLine{        \textcolor{keywordflow}{if} (err)}
\DoxyCodeLine{           printf(\textcolor{stringliteral}{"{}Error during test function: \%s\(\backslash\)n"{}},}
\DoxyCodeLine{                  \mbox{\hyperlink{group__Eina__Error__Group_gac420af42486bcbb879c4be67eacc6c2a}{eina\_error\_msg\_get}}(err));}
\DoxyCodeLine{     \}}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (!test(-\/1))}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        \mbox{\hyperlink{group__Eina__Error__Group_ga95b3cbb33e987e7d92a81ea785001686}{Eina\_Error}} err;}
\DoxyCodeLine{}
\DoxyCodeLine{        err = \mbox{\hyperlink{group__Eina__Error__Group_gaf1afffc7dc1e11101f47c5d14d9c5347}{eina\_error\_get}}();}
\DoxyCodeLine{        \textcolor{keywordflow}{if} (err)}
\DoxyCodeLine{           printf(\textcolor{stringliteral}{"{}Error during test function: \%s\(\backslash\)n"{}},}
\DoxyCodeLine{                  \mbox{\hyperlink{group__Eina__Error__Group_gac420af42486bcbb879c4be67eacc6c2a}{eina\_error\_msg\_get}}(err));}
\DoxyCodeLine{     \}}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__Main__Group_ga5bf35513199d5220341437c05696285d}{eina\_shutdown}}();}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} EXIT\_SUCCESS;}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 