| 1 | // DiagInfoTest.cpp : Defines the entry point for the console application. | 
|---|
| 2 | // | 
|---|
| 3 |  | 
|---|
| 4 | #include "stdafx.h" | 
|---|
| 5 |  | 
|---|
| 6 | #include <boost/exception/all.hpp> | 
|---|
| 7 |  | 
|---|
| 8 | #include <iostream> | 
|---|
| 9 | #include <sstream> | 
|---|
| 10 |  | 
|---|
| 11 | class MyException : public virtual std::exception, public virtual boost::exception | 
|---|
| 12 | { | 
|---|
| 13 | }; | 
|---|
| 14 |  | 
|---|
| 15 | void PrintExInfo() | 
|---|
| 16 | { | 
|---|
| 17 | std::stringstream s; | 
|---|
| 18 |  | 
|---|
| 19 | std::string shortInfo = boost::current_exception_diagnostic_information(false); | 
|---|
| 20 | s << "Short info(" << shortInfo.size() << "): " << shortInfo << "\n"; | 
|---|
| 21 |  | 
|---|
| 22 | std::string longInfo = boost::current_exception_diagnostic_information(); | 
|---|
| 23 | s << "Long info(" << longInfo.size() << "): " << longInfo << "\n"; | 
|---|
| 24 |  | 
|---|
| 25 | std::cout << s.rdbuf(); | 
|---|
| 26 | } | 
|---|
| 27 |  | 
|---|
| 28 | int main(int argc, char* argv[]) | 
|---|
| 29 | { | 
|---|
| 30 | try | 
|---|
| 31 | { | 
|---|
| 32 | throw std::exception(); | 
|---|
| 33 | } | 
|---|
| 34 | catch (...) | 
|---|
| 35 | { | 
|---|
| 36 | PrintExInfo(); | 
|---|
| 37 | } | 
|---|
| 38 |  | 
|---|
| 39 | try | 
|---|
| 40 | { | 
|---|
| 41 | BOOST_THROW_EXCEPTION(std::exception()); | 
|---|
| 42 | } | 
|---|
| 43 | catch (...) | 
|---|
| 44 | { | 
|---|
| 45 | PrintExInfo(); | 
|---|
| 46 | } | 
|---|
| 47 |  | 
|---|
| 48 | try | 
|---|
| 49 | { | 
|---|
| 50 | BOOST_THROW_EXCEPTION(MyException()); | 
|---|
| 51 | } | 
|---|
| 52 | catch (...) | 
|---|
| 53 | { | 
|---|
| 54 | PrintExInfo(); | 
|---|
| 55 | } | 
|---|
| 56 |  | 
|---|
| 57 |  | 
|---|
| 58 | return 0; | 
|---|
| 59 | } | 
|---|
| 60 |  | 
|---|
| 61 |  | 
|---|