Boost logo

Boost Users :

Subject: [Boost-users] [Exceptions] Custom type in error_info value?
From: Andrew Chinkoff (achinkoff_at_[hidden])
Date: 2010-02-28 15:39:46


This is the test program I would like to be explained to me:

#include <iostream>
#include <string>
#include <boost/exception.hpp>

struct MyException: virtual boost::exception{ };

class MyClass
{
    char* s;
public:
    MyClass(const char* msg) : s(strdup(msg)){ }
    MyClass(const MyClass& c){ s = strdup(c.s); }
    ~MyClass(){ free(s); }
};

void main()
{
    MyException ex;
    ex << boost::error_info<struct my_tag1, MyClass>("qweqwe");
    ex << boost::error_info<struct my_tag2, std::string>("asdasd");
    std::cout << boost::diagnostic_information(ex);
}

This is the program output:

> Throw in function (unknown)
> Dynamic exception type: struct MyException
> [PAUmy_tag1@?1?main@] = [ type: ?AV?$error_info_at_Umy_tag1@?1?main_at_VMyClass
@@@boo
> t@@, size: 8, dump: 50 69 10 01 b8 18 7f 00 ]
> [PAUmy_tag2@?1?main@] = asdasd

So, my question: what should I do with 'MyClass' to see the output like
this:

> Throw in function (unknown)
> Dynamic exception type: struct MyException
> [PAUmy_tag2@?1?main@] = qweqwe (Wow !!! Terrible dump is replaced with
readable string here !!!???)
> [PAUmy_tag2@?1?main@] = asdasd

Thanks, Andrew.



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