When a function fails, depending on the return value, you may receive a false
or a NULL
return. To learn what went wrong and why the function failed, you can
use check the errno
:
#include <errno.h>
...
if(!ctorm_app_run(app, argv[1])){
if(errno == BadAddress)
ctorm_fail("you specified an invalid address");
else
ctorm_fail("something else went wrong: %d", errno);
return EXIT_FAILURE;
}
See errors.h for the full list of error codes.
To get the string description of an error, you can use ctorm_geterror
:
if(!ctorm_app_run(app, "0.0.0.0:8080")){
ctorm_fail("something went wrong: %s", ctorm_geterror());
return EXIT_FAILURE;
}
Or you can get the description of a specific error code:
ctorm_info("BadAddress: %s", ctorm_geterror_from_code(BadAddress));