stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: svn commit: r418319 - /incubator/stdcxx/trunk/tests/strings/21.string.io.cpp
Date Wed, 05 Jul 2006 00:14:43 GMT
Anton Pevtsov wrote:
> Martin, I have a question about the exceptions thrown from the streambuf
> virtual functions. The standard says (27.5.2.4.3 p1) that "underflow or
> uflow might fail by throwing exception prematurely" but the exception
> type is not specified.

Yes, the streambuf virtual function can throw an exception of any
type (since it can be overridden by the user). For example, it can
throw bad_alloc if the function fails to allocate memory, or it can
throw some user-defined exception type for some network error.

> Shall we throw something just to verify the
> exception safety or shall we throw some specific exception?

The type of the object doesn't really matter, just as long as it's
distinguishable from the types that can be thrown by the library
itself. I.e., we shouldn't throw std::bad_alloc, std::ios::failure,
or any other type based on std::exception. The enumeration value
thrown by the MyStreambuf class is probably okay, but we could
throw something more sophisticated, e.g., an object akin to the
BadSharedAlloc class thrown by SharedAlloc. In fact, we might want
to have a single throw function, say rw_throw(ExceptionId id, const
char* file, int line, const char *function, const char *format, ...)
to throw a particular exception from a test driver's class or function.
That way we would have a single point of throwing an exception in the
whole test driver which is useful for setting breakpoints and to
reduce code duplication.

Martin

Mime
View raw message