Topic: Containers and exceptions


Author: John Max Skaller <maxtal@suphys.physics.su.oz.au>
Date: 1995/12/11
Raw View
Marian Hellema <marian@atcmp.nl> wrote:
>
>Hello,
>
>I am wondering if any of the containers in the standard library
>can throw exceptions.
>In the working paper the only container for which exceptions
>are specified is bitset.

  Bitset isn't parameterized on an unknown user type.

>This suggests that none of the other containers throws exceptions.
>If this is correct: why not?

  Other containers _may_ throw exceptions wherever behaviour is
undefined by the Standard, and _usually will_ throw exceptions
generated by manipulating objects of the contained type (if any).

  In a few cases exceptions are thrown in specified circumstances,
however there's no exception specification (which would
_prevent_ other exceptions being thrown).


--
John Max Skaller               voice: 61-2-566-2189
81 Glebe Point Rd              fax:   61-2-660-0850
GLEBE NSW 2037                 email: maxtal@suphys.physics.oz.au
AUSTRALIA                      email: skaller@maxtal.com.au



[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]






Author: Marian Hellema <marian@atcmp.nl>
Date: 1995/12/06
Raw View
Hello,

I am wondering if any of the containers in the standard library
can throw exceptions.
In the working paper the only container for which exceptions
are specified is bitset.
This suggests that none of the other containers throws exceptions.
If this is correct: why not?

It would seem reasonable to me, for example: vector's operator[]
throws an exception if you use an index greater than the size()
of the vector. (Similar to the class string, whose memberfunction
at() can throw out_of_range).
Or: a length_error exception if you try to resize a container to
a size which exceeds max_size(). (Again: similar to class string).

Thanks,
Marian
--
----------------------------------------------------------------------
Marian Hellema            AT Computing, UNIX training and consultancy
email: marian@atcmp.nl    P.O. Box 1428, 6501 BK Nijmegen
phone: +31 24 3527225     the Netherlands



---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]





Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/12/07
Raw View
In article ke0@info.uci.kun.nl, Marian Hellema <marian@atcmp.nl> writes:
>
>I am wondering if any of the containers in the standard library
>can throw exceptions.
>In the working paper the only container for which exceptions
>are specified is bitset.
>This suggests that none of the other containers throws exceptions.

No, it's the reverse. If the specification of a function in the standard
library has no throw-specification, the function is allowed to throw any
exception. (That is true for any function, of course, standard or
user-defined.)

A function in a container class could potentially throw any exception,
depending on the characteristics of user-defined classes provided as
template arguments.

---
Steve Clamage, stephen.clamage@eng.sun.com




---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]