 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Paul D. DeRocco Guest
|
Posted: Thu Apr 01, 2004 7:49 am Post subject: Re: Exception hierarchy |
|
|
| Quote: | "Alberto Barbati" <AlbertoBarbati (AT) libero (DOT) it> wrote
1) runtime_error and logic_error are highly dependent on the library
implementation as they both depend on std::string. Having language-level
features such as dynamic_cast and typeid depend so much on the library
implementation is not acceptable. For this reason the std::exception
class is so light-weight and have no other library dependencies.
|
That makes sense.
| Quote: | 2) throwing a runtime_error/logic_error requires the dynamic allocation
of one or more strings and it might be simply impossibile to do that in
those peculiar situations that requires "low-level" exceptions. This is
especially true for bad_alloc: if there's no memory to accomplish an
allocation request, there might be no memory for the string too.
|
The implementations I've used all have some pre-allocated space for the
temporary exception objects themselves, so the difficult part is allocating
the subsidiary object that contains the data. But that can be solved by
using a reference counting implementation like Gnu does, and initializing
the string from a pre-existing static one.
| Quote: | 3) it is not self-evident whether they should derive from runtime_error
or from logic_error
|
I would say bad_alloc is a runtime_error, and the others are logic_errors,
generally speaking.
Another missing feature of exceptions, in my view, is a virtual clone()
function. This would be useful because an exception object disappears as
soon as the catch block is exited, and it is often useful to save the
exception for later processing. About all you can save now is the what()
string, and Gnu doesn't even put enough info into the string to completely
identify the exception if the type information is gone.
--
Ciao, Paul D. DeRocco
Paul mailto:pderocco (AT) ix (DOT) netcom.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|