Exceptions are signaled by throwing a rwsf::Exception or one of its derived classes.
Exceptions fall in the following general categories:
General and XML exceptions, including allocation errors, external and internal errors, threading exceptions, and XML parsing errors.
Servlet and Web service-specific, such as WSDL exceptions and faults
Various network exceptions
It is generally preferable to catch the most specific exception possible, so that it will not be confused with other exceptions that might indicate real errors.
As described in Chapter 7, all HydraExpress system messages are stored in external UTF-8 message catalogs. A central rwsf::MessageCatalogManager loads the strings at runtime, and provides the ability to switch languages dynamically. Class rwsf::LocalizedMessage is the primary class used for accessing a localized string.
You can construct an rwsf::Exception instance from an rwsf::LocalizedMessage. For example:
try { throw rwsf::Exception(RWSF_EINFO, LocalizedMessage(RWSF_MSG_UNEXPECTED_ERROR)); } catch (const rwsf::Exception& e) { std::cout << "Message: " << e.why() << std::endl; std::cout << "Function: " << e.getFunctionName() << std::endl; std::cout << "File: " << e.getFileName() << std::endl; std::cout << "Line: " << e.getLineNumber() << std::endl; }
Which produces this output (on Windows):
Message: [UNEXPECTED_ERROR] Unexpected Exception Function: void __thiscall ExceptionTest::testCtor(void) File: ..\ExceptionTest.cpp Line: 31
Note that the message identifier -- UNEXPECTED_ERROR, in this example -- is automatically prepended to the exception string.
RWSF_EINFO is a macro that expands to a temporary instance of rwsf::ExceptionInfo, with the proper preprocessor directives to populate the filename, function name, and line number fields in the exception.
See Chapter 7 for more information on how to set the default local, build message catalogs, access localized messages, and change the locale dynamically.
For services that use default data mappings and with the -stl option, message text is returned for exceptions derived from std::exception and rwsf::Exception, so you will want to be prepared to catch these exceptions.
For services that use SourcePro, message text is returned not only for std::exception and rwsf::Exception but also for RWxmsg, so exception-safe code should be prepared to catch and handle these exception types.
© Copyright Rogue Wave Software, Inc. All Rights Reserved. All Rights Reserved. Rogue Wave is a registered trademark of Rogue Wave Software, Inc. in the United States and other countries. HydraExpress is a trademark of Rogue Wave Software, Inc. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.