What will be printed in the following code?
#include <iostream>

class Locker {
    public:
        ~Locker() { throw 2; }
};

int main() {
    try {
        Locker locker;
        throw 1;
    } catch (int a) {
        std::cout << a;
    }
    return 0;
}
Explanation
If an object destructor is called due to stack spin-up as a result of calling an exception, then exiting such a destructor by throwing an exception is guaranteed to cause the call of the terminate() function. As a consequence, the program will crash with an error. If the exception excited in such a destructor is "caught", the call of terminate() will not be made.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести