Thorsten Behrens wrote:
Hi *,there are a few recurring patterns for error handling in UNO API implementations, three of which I'll address here: 1. input validation/precondition checks. Violating one of those usually leads to an IllegalArgumentException being thrown. 2. Runtime errors, usually signalled by a RuntimeException (this is comprised of a whole bunch of error conditions, ranging from logic errors/invariant violations to resource exhaustion) 3. exception-less error reporting, usually via boolean return values For all cases, one might want to see an assertion in debug builds, if only to make sure the caller handles the error condition correctly. So, I'd like to propose a bunch of macros, quite similar to the OSL_ASSERT/OSL_ENSURE family, that, in the case of an error, show an assertion in debug builds, and always throw a corresponding exception: ---%<----------------------------------------------------------------- #define VALIDATE_AND_THROW(c, m, ifc, arg_num) if( !(c) ) { \ OSL_ENSURE(false, m); \ throw ::com::sun::star::lang::IllegalArgumentException( \ ::rtl::OUString::createFromAscii(BOOST_CURRENT_FUNCTION) + \ ::rtl::OUString::createFromAscii(",\n"m), \ ifc, \ arg_num ); } #define ENSURE_AND_THROW(c, m, ifc) if( !(c) ) { \ OSL_ENSURE(false, m); \ throw ::com::sun::star::uno::RuntimeException( \ ::rtl::OUString::createFromAscii(BOOST_CURRENT_FUNCTION) + \ ::rtl::OUString::createFromAscii(",\n"m), \ ifc ); } #define ENSURE_AND_RETURN(c, m) if( !(c) ) { \ OSL_ENSURE(false, m); \ return false; } ---%<----------------------------------------------------------------- Is this useful, and if yes, where to place it? It needs UNO, so osl is too low, and it currently employs boost, which afaik rules out udk...
Yes, the interface of URE is kept clear of boost for now, so porting and udk are ruled out.
Personally I'm undecided whether some macros like these are really needed. At the very least, I would rename them from "_AND_" to "_OR_."
-Stephan --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
