and I have a poor knowledge about exceptions and handling. I have a code defined around the class Polyline and Point. In this case, Point depends on Polyline. And there are operator overloading methods described. I'm having trouble in one of them due to the "throw" , as I don't get it very well.
My code is:
//defining the operator overloading method for []
Point & Polyline::operator[](int index) const {
//defining the exception (why don't use "try"?)
if (index >= num) {
throw out_of_range("Index out of range");
}
// if everythings OK, it returns the object reference
return p[index];
}
So, questions.
What is throw for exactly here (I know it's for give an exception for index out of range) but why use throw instead of a simple advise with cout or similar? and why don't use try?
Thanks