This is a basic question after coding try which covers a range of c/c++ statements.
If the catch block is entered, how do I know which statement was the culprit?
This is a basic question after coding try which covers a range of c/c++ statements.
If the catch block is entered, how do I know which statement was the culprit?
Given the code
try {
if (a)
throw 0;
else if (b)
throw 0;
else if (c)
throw 0;
throw 1;
} catch (int i) {
// << here
}
If i is 0, there is no language-specified mechanism to tell which throw 0 threw. We can only distinguish between 0 and 1 throws. There are compiler specific hacks (How can I print stack trace for caught exceptions in C++ & code injection in C++) but nothing standard.