
On Sat, Jul 21, 2012 at 2:50 PM, Andreas M. Iwanowski
Dear boost experts.****
** **
We are using boost::exception in a project of ours, and are trying to extract some information from an exception****
to display to the user.****
** **
For example, diagnostic_information(e) returns this:****
** **
d:\projects\<project>\ClassName.cpp(376): Throw in function void __thiscall ClassName::CInetExceptionHandler<struct ClassName::BadLoginException>(class CInternetException *) const****
Dynamic exception type: class boost::exception_detail::clone_impl<struct ClassName::BadLoginException>****
std::exception::what: Unknown exception****
[struct tag_implementation_ClassName_SpecificInfo_errstr *] = Error: 12014 Context: 0 Message: The password was not allowed****
** **
[struct tag_interface_CDataInterface_errstr *] = ClassName reports: Bad FTP login****
** **
** **
What I want is to extract "Error: 12014 Context: 0 Message: The password was not allowed" or "ClassName reports: Bad FTP login"****
from that exception.****
** **
However, these exceptions may be generated in DLLs that the main program know nothing about.****
** **
To simplify, here is what I do and want ot be happening:****
** **
1. Main program calls method in DLL****
2. Main program knows this method can throw expections of type boost::exception****
3. Main program catches such exception****
4. Main program obtains string that is user-friendly from this exception** **
Use boost::get_error_info. See www.boost.org/doc/libs/release/libs/exception/doc/get_error_info.html. Ideally, error messages shouldn't be passed in exception objects. Instead, pass the information that the catch site needs to format the message. So, I'd suggest that the "4. Main program obtains a string that is user-friendly" should probably be "4. Main program formats a user-friendly message out of the error_info objects stored in the exception." Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode