Throwing out of range exception in C++

c++, exception

Solution

Replace `throw std::out_of_range;` with `throw std::out_of_range ("blah");`. I.e. you need to create an object, you cannot throw a type.

Problem

This code works; ``` int at(int index) { if(index < 1 || index >= size) throw 0; return x[index]; } ``` Yet this doesn't ``` int at(int index) { if(index < 1 || index >= size) throw std::out_of_range; return x[index]; } ``` I get the error "expected primary expression before ';'". Now... it surprises me because I know std::out_of_range exists and I have ``` #include <stdexcept> ```

Original source