In C++ it is impossible to have two exceptions "in flight" at the same time. If that condition ever arises (e.g. by a destructor throwing during stack unwinding), the program is terminated (with no way to catch the second exception).
What you can do is make a suitable exception class, and throw that. For example:
class my_exception : public std::exception {
public:
my_exception() : x(0), y(0) {} // assumes 0 is never a bad value
void set_bad_x(int value) { x = value; }
void set_bad_y(int value) { y = value; }
virtual const char* what() {
text.clear();
text << "error:";
if (x)
text << " bad x=" << x;
if (y)
text << " bad y=" << y;
return text.str().c_str();
}
private:
int x;
int y;
std::ostringstream text; // ok, this is not nothrow, sue me
};
Then:
void testing(int &X, int &Y)
{
// ....
if (X>5 || Y>10) {
my_exception ex;
if (X>5)
ex.set_bad_x(X);
if (Y>10)
ex.set_bad_y(Y);
throw ex;
}
}
Anyway you should never throw raw strings or integers or the like--only classes derived from std::exception (or perhaps your favorite library's exception classes, which hopefully then derive from there, but may not).