List:MySQL++« Previous MessageNext Message »
From:me22 Date:October 10 2008 11:07pm
Subject:[documentation] Confusion: vector::operator[] and exceptions
View as plain text  
In the user manual, 3.4 Exceptions says the following:
"The largest set of non-optional exceptions are those from the
Standard C++ Library. For instance, if your code said "row[21]" on a
row containing only 5 fields, the std::vector underlying the row
object will throw an exception. (It will, that is, if it conforms to
the standard.) You might consider wrapping your program's main loop in
a try block catching std::exceptions, just in case you trigger one of
these exceptions."

This has me confused.  vector::operator[] does not throw exceptions
for out-of-range indexes, so I was surprised that Row does.

I looked at the source for Row
and it seems that operator[] is actually calling the vector's at.
That seems like a waste of time, since it's already checked that the
index is valid.  And in the case that the index *is* out of range, it
throws a custom exception, not the one from vector::at, contrary to
the documentation.

~ Scott
[documentation] Confusion: vector::operator[] and exceptionsme2211 Oct
  • Re: [documentation] Confusion: vector::operator[] and exceptionsWarren Young11 Oct
    • Re: [documentation] Confusion: vector::operator[] and exceptionsRick Gutleber13 Oct
  • Re: [documentation] Confusion: vector::operator[] and exceptionsWarren Young8 Nov