mheily / jobd

A job management framework
Other
143 stars 15 forks source link

throwing exceptions inside a library considered harmful #81

Open mheily opened 8 years ago

mheily commented 8 years ago

libjob needs to catch exceptions and gracefully error out, because otherwise it will kill the program in unusual ways.

Example:

static std::string get_user_datadir() 
{
    const char *home = getenv("HOME");
    if (!home) {
        throw "Missing HOME directory environment variable";    
    }
mheily commented 8 years ago

Also, we should stop throwing std::strings, and start throwing custom exceptions that inherit from std::exception. It is very lame to have to catch both std::string AND std::exception everywhere.