\hypertarget{eina_error_01_8c-example}{}\doxysection{eina\+\_\+error\+\_\+01.\+c}
Of course, instead of printf(), \mbox{\hyperlink{group__Eina__Log__Group_ga2ad47c77225cbcf8d35840547b5bbbe4}{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_gad1a7035e62df4f3f57c690bb1159dc01}{eina\_error\_set}}(0);}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__Error__Group_gad1a7035e62df4f3f57c690bb1159dc01}{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_gad1a7035e62df4f3f57c690bb1159dc01}{eina\_error\_set}}(0);}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (n < 0)}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        \mbox{\hyperlink{group__Eina__Error__Group_gad1a7035e62df4f3f57c690bb1159dc01}{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_gafee4bfc0e509b6ffed6598edf6f4b3de}{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_ga4e67b3ce519e086fad1962c0499201b2}{eina\_error\_msg\_static\_register}}(\textcolor{stringliteral}{"{}Negative number"{}});}
\DoxyCodeLine{   MY\_ERROR\_NULL = \mbox{\hyperlink{group__Eina__Error__Group_ga4e67b3ce519e086fad1962c0499201b2}{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_ga010057192a0735339e46b6f8f69b7345}{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_ga54953b3f118ad981cb27ef3ac3d77b17}{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_ga010057192a0735339e46b6f8f69b7345}{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_ga54953b3f118ad981cb27ef3ac3d77b17}{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_ga010057192a0735339e46b6f8f69b7345}{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_ga54953b3f118ad981cb27ef3ac3d77b17}{eina\_error\_msg\_get}}(err));}
\DoxyCodeLine{     \}}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__Main__Group_ga2c8b4020427108a30c44707af22c99d3}{eina\_shutdown}}();}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} EXIT\_SUCCESS;}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 