The C ++ Standard Library defines some types of exceptions, such as std::exception, std::bad_allocand std::logic_error. Do we suppose or allow them to be used in our own code in general?
Take a concrete example. We define a type Arraythat contains a fixed number intand throws a std::out_of_rangeout of range access. It has a member function Array::operator[](size_t i), which is defined as follows:
int& Array::operator[](size_t i) {
if (i >= size)
throw std::out_of_range({ "out of range" });
return array[i];
}
I think that we, of course, can use them (the standard does not actually prohibit it), but it looks like a protracted out of context. IMO, it looks like a constant
const unsigned int percentFactor = 100;
which is used to allocate memory:
char* ptr = new char[percentFactor];
percentFactor float/double, . 100 char s, , LOC . . std::out_of_range , , , .
, //API ?