eas wrote:
How to catch the following exceptions?
With a catch() block, as Victor said.
Failure in an assignment operator
Assignment operators are source-code constructs, which don't exist at
runtime. So I guess you mean a user-defined operator=(). In that case,
the function would have to throw an exception in order for it to be
caught, and you'd simply catch that exception as you would any other.
Detection of an out-of-bound index in a user-defined array
What do you mean by "user-defined array"? if you are talking about
built-in arrays, there's no standard exception that is thrown - an
out-of-bound access simply invokes undefined behavior.
If you defined an array class, you could check for out-of-bound accesses
and throw whatever exception you want. You would catch this the same way
you catch any other exception.
Range-checked access to a vector
If you use the vector::at() function, an exception will be thrown for an
out-of-range access, as Ron mentioned. operator[] silently invokes
undefined behavior on an out-of-range access.
In both the array and vector cases, you could feasibly create your own
range-checked iterators that throw an exception of your choice.
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.