Question: I use a (C) library with functions taking different parameters but always returning an int greater than zero in case of error:

```
int functionA(int param1, char param2); /* return an error code on failure, 0 otherwise */
int functionB(LIB_BOOLEAN param1);      /* return an error code on failure, 0 otherwise */
// ...

```

I would like to turn them all to be exception ready:

```
if (functionA(param1, param2) > 0)
{ throw std::runtime_error("Method failed"); }

```

Is it possible to write a template to do it once for all method ?

EDIT:
The idea is to avoid checking the result for each functions every time I use them.

Answer: 
I know I'll get downvoted for this, but I honestly think this is one case where the preprocessor can usefully be used:

```
#define CHECK( fn ) \
    { \
        if( fn > 0 ) { \
            throw "problem"; \
        } \
    } 

int f(int x) {
    return x - 1;
}

int main() {
    CHECK( f(42) );
}

```

It's clear, it's short, it's simple, and it could be made to make use of the `__LINE__`, `__FILE__` and other pre-defined macros, which you can't do with templates.
Here’s one approach that doesn’t require changing call sites. Assuming these C functions all have the same convention for return codes, you can write a wrapper that converts the return code to an exception.

```
inline void checked(const char *name, int result) {
    if (result > 0)
        throw std::runtime_error(name);
}

```

Then introduce a preprocessor definition for each function.

```
#define functionA(...) checked("functionA", functionA(__VA_ARGS__))

```

This works because `functionA` will not be expanded within the definition of the `functionA` macro. And variadic macros are standard since C++11.