stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anton Pevtsov" <Ant...@moscow.vdiweb.com>
Subject RE: svn commit: r418319 - /incubator/stdcxx/trunk/tests/strings/21.string.io.cpp
Date Wed, 05 Jul 2006 15:38:19 GMT
Martin Sebor wrote:
> 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.

I am working on this. I suggest to implement this function in a separate
header (say rw_exception.h).

Also I implemented the exception safety loop in 21.string.io in the same
to other tests way but faced with a perfomance problem.
The streambuf virtual functions for long strings (say "x@4096") are
called very often and as a result the test is performed very slowly. I
suggest to reduce the thrown exception count to 3 or 5 for the long
strings (throw on first and last elements and on several in the middle)
and leave this count unchanged for short strings (the streambuf will
throw on each element).
What do you think about this?


Thanks,
Anton Pevtsov


-----Original Message-----
From: Martin Sebor [mailto:sebor@roguewave.com] 
Sent: Wednesday, July 05, 2006 04:15
To: stdcxx-dev@incubator.apache.org
Subject: Re: svn commit: r418319 -
/incubator/stdcxx/trunk/tests/strings/21.string.io.cpp


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