Each source file of my library (libA) includes an in_err.h file.
This file defines an enum for every possible error, and an array of string describing the corresponding error.
There is a function get_err_mess() which returns the error message corresponding to the error enum.
in_err.h
typedef enum {
E_ERR_NOERROR = OK, //OK=0
E_ERR_1 = E_ERR_BADPARAM,
...
E_ERR_MAX
} ERROR;
const char *error_description[] = {
"No error.",
"Bad parameter.",
...
"Max error enum reached.",
};
const char * get_err_mess(ERROR err){
...
return err_mess;
}
Every functions of my library (libA) returns an ERROR type.
libA.a
#include "in_err.h"
ERROR func1()
{
ERROR err = OK;
...
return err
}
The main program calls functions from libA and displays error message if any.
main.c
#include "in_err.h"
#include "headerfromlibA.h"
int main()
{
ERROR err = OK;
err = func1()
if (!err){
err = func2()
}
if(err){
printf("Error: %s\n", get_err_mess(err));
}
return err;
}
Now I want to make another library (libB) with the same kind of error management but with its own types of errors.
My problem is that I would have two get_err_mess() functions with potentially the same error id.
I'd like to have a single get_err_mess() to manage errors from libA and libB.
What would you recommend ?
The only solution I see is to set a range of error for each library... but I don't like it