Catching bad allocation

I'm creating an array dynamically, and I'm trying to catch it failing, though it doesnt seem to. Even though I give it absurd sizes. Am I doing something wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int szInput;
    cout << "How big do you want your array?\n";
    cin >> szInput;

    int *arr;
    try{
        arr = new int[szInput];
    }catch(std::exception &e)
    {
        cout << "Error: " << e.what();
        return 1;
    }

    cout << "Success";


EDIT:
I can get it to fail if I enter a negative number, but not if I enter some huge number. Is this normal behavior?
Last edited on
What value are you using? I get failure with 1000000000.
Ah that does work. I was just using random numbers before, which would either get stopped by the input validation I put in, or it would go through.
Topic archived. No new replies allowed.