This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115f. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-12-06


805. Which exception to throw for overflow in array size calculation

Section: 7.6.2.8  [expr.new]     Status: CD2     Submitter: UK     Date: 3 March, 2009

N2800 comment UK 72
N2800 comment UK 192

[Voted into WP at July, 2009 meeting as part of N2932.]

Throwing std::length_error (7.6.2.8 [expr.new] paragraph 7) for an attempt to allocate a too-large array brings in too much of the Standard library. A simpler exception, like std::bad_alloc, should be thrown instead.

Notes from the March, 2009 meeting:

The CWG was in favor of throwing an exception derived from std::bad_alloc. This would be upwardly compatible; it would be harmless for programs that currently catch std::bad_alloc, but would allow programs to treat the calculation overflow case separately if they wish.