Extracting "friendly" information from boost::exception
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 Has anyone acccomplished this or knows how to extract the information from above (ideally not by parsing the string?) Alternatively, could I somehow fill the std::exception::what and then get that information out of boost::exception somehow? Thanks everyone! Mit freundlichen Gr??en / With best regards Andreas Iwanowski - IT Administrator www.awato.dehttp://www.awato.de | namezero@afim.infomailto:namezero@afim.info T: +49 (0)2133 2969 28 | F: +49 (0)2133 2969 69 awato Software GmbH | Salm Reifferscheidt Allee 37 | D-41540 Dormagen avisor-Support | T: +49 (0)621 6094 043 | F: +49 (0)621 6071 447 [awato Software GmbH] [cid:qrCode-58869986-5cab-4997-b473-f0c11a0058ad21bff0] Gesch?ftsf?hrer: Ursula Iwanowski | HRB: Neuss 7208 | VAT-no.: DE 122796158
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
participants (2)
-
Andreas M. Iwanowski
-
Emil Dotchevski