I'm following a free course that uses C++98 by default. I installed VS Code on windows, along with MSYS. I can't seem to get C++98 to work on it because rather than telling me anything useful, it just says that using throw(type) is deprecated in C++17. So, I used g++ on the command prompt with -std=c++98, and it works. Then I run the exe, and it terminates, just like with the 2 online IDEs I've tried. I've tried the cpp.sh and Ideone online IDEs.

It seems that no matter what catch I use and no matter where I place the try, catch statements, a logic_error exception isn't caught, and it terminates the program.

I cannot for the life of me figure out why.

This is one of their test questions. The question is what happens when this code is run? Well, it seems like the answer must be it terminates the program, but I don't know why. I like to solve the why so I know why the code is doing it. But I cannot catch the exception to see where it's able to skip all the catch statements that I've put everywhere!

I know the answer is very simple, but I don't know what it is.

Code:
#include <iostream>
#include <exception>
#include <stdexcept>

using namespace std;

class X : public logic_error 
{
    public:
        X() : logic_error("logic_error in X class")  {}
        
};

void z() throw(X)
{
    throw new logic_error("logic_error in z()");
}

int main() 
{
    try {
        
        X x;
        
        try{
            z();
        }
        catch(X &i) { cout << i.what(); }
        catch(exception &a) { cout << "This is catch(exception &a): " << a.what(); }
        catch(logic_error &lr) { cout << "This is catch(logic_error &lr): " << lr.what(); }
        catch(...) { cout << "This is catch(...)"; }
    }
    catch(...) { cout << "try surrounds all code in main except the return, this catch is at the bottom of that."; }
        
    return 0;
}