hybang hybang -4 years ago 106
C++ Question

c++ exception list with array?

I have some exception during my work.

At frist time, i Handle 1~2 exceptions like

if (strcmp(d_name, "abc") == 0) {
continue;
}
if (strcmp(d_name, "def") == 0) {
continue;
}


but now i have more than 10 exceptions to handle.

so I am trying to find to make exceptions array? list? something...

exceptions {"abc", "def", "xyz", ...}

if (strcmp(d_name, exceptions) == 0) {
continue;
}


I hope to find this kind of work. is there any good way to me?

Answer Source

An array of strings;

char **excepts = {"abc", "def", "xyz", ..., ""}; // end with ""

bool found=false;
for(int i=0; excepts[i][0]; i++)
{
    if (strcmp(d_name, exceptions) == 0) {
        found = true;
        break;
    }
}

if(found) continue; 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download