| 1 | #include <string>
|
|---|
| 2 | #include <iostream>
|
|---|
| 3 |
|
|---|
| 4 | #include <boost/exception.hpp>
|
|---|
| 5 | #include <boost/lexical_cast.hpp>
|
|---|
| 6 |
|
|---|
| 7 | typedef boost::error_info<struct os_error_info_tag, int> os_error_info_base;
|
|---|
| 8 |
|
|---|
| 9 | class os_error_info : public os_error_info_base
|
|---|
| 10 | {
|
|---|
| 11 | public:
|
|---|
| 12 | os_error_info(int const& err_code)
|
|---|
| 13 | : os_error_info_base(err_code) {}
|
|---|
| 14 |
|
|---|
| 15 | private:
|
|---|
| 16 | std::string value_as_string() const
|
|---|
| 17 | {return "Error code: " + boost::lexical_cast<std::string> (value());}
|
|---|
| 18 | };
|
|---|
| 19 |
|
|---|
| 20 | int main(int argc, char* argv[])
|
|---|
| 21 | {
|
|---|
| 22 | try
|
|---|
| 23 | {
|
|---|
| 24 | throw boost::enable_error_info(std::exception("value_as_string test")) <<
|
|---|
| 25 | os_error_info(10);
|
|---|
| 26 | }
|
|---|
| 27 | catch (boost::exception const& ex)
|
|---|
| 28 | {
|
|---|
| 29 | std::cerr << boost::diagnostic_information(ex) << std::endl;
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | // std::cin.get();
|
|---|
| 33 | return 0;
|
|---|
| 34 | }
|
|---|