Boost logo

Boost Users :

Subject: Re: [Boost-users] [Test] Making use of boost::exception_diagnostic_information and friends
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2009-08-10 22:29:13


On Mon, Aug 10, 2009 at 5:37 PM, Gennadiy Rozental<rogeeff_at_[hidden]> wrote:
> Does this require some kind of RTTI?

Some kind, yes, to provide type safety. If the built-in RTTI is
disabled, Boost Exception uses the same workaround used by shared_ptr.

>> Here is an example of what this could display:
>>
>> example_io.cpp(83): Throw in function class boost::shared_ptr<struct
>> _iobuf> __cdecl my_fopen(const char *,const char *)
>> Dynamic exception type: class
>> boost::exception_detail::clone_impl<class fopen_error>
>> std::exception::what: example_io error
>> [struct errno_ *] = 2, OS says "No such file or directory"
>> [struct file_name_ *] = tmp1.txt
>> [struct function_ *] = fopen
>> [struct open_mode_ *] = rb
>
> 1. This is not very readable at best?

I'd agree that it isn't user-friendly; to a programmer it should speak
volumes. :)

>> The string is pretty
>> much guaranteed to be ugly to look at yet rather informative. :)
>
> I believe you gave up too early. You should not take over formatting of the
> error messages (you can provide default I guess)

This is *not* an error message, it is an automatically-generated
diagnostic message for exceptions that should have been handled (to
generate a proper user message) but weren't. It is about as pretty as
a core dump, and about as useful.

> 2. What if I want to generate XML log instead?

You'd just have to filter the returned string for < and >, etc.

> 3. What if I do not want to display anything at all, but store in some file?

It's a string, you can do with it whatever you want.

> After some testing it seems that BOOST_THROW_EXCEPTION only works with types
> inherited from std::exception.

This requirement comes from boost::throw_exception, to support
-fno_exceptions builds, where the user is required to define a
non-template std::exception overload for boost::throw_exception.
BOOST_THROW_EXCEPTION calls boost::throw_exception and hence has the
same requirements.

Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net