Date: Monday, November 28, 2005 @ 19:23:55
Author: marc
Path: /cvsroot/carob/carob/test
Modified: CarobProtector.hpp (1.5 -> 1.6)
Now catching all CarobException (s). Simplified and factorized code.
--------------------+
CarobProtector.hpp | 74 +++++++++++++++++++++++++++++++--------------------
1 files changed, 46 insertions(+), 28 deletions(-)
Index: carob/test/CarobProtector.hpp
diff -u carob/test/CarobProtector.hpp:1.5 carob/test/CarobProtector.hpp:1.6
--- carob/test/CarobProtector.hpp:1.5 Mon Nov 28 16:17:58 2005
+++ carob/test/CarobProtector.hpp Mon Nov 28 19:23:55 2005
@@ -27,15 +27,19 @@
static const wstring BEPREFIX(L"BackendException catched by CarobProtector: ");
-static const wstring CEPREFIX(L"CarobException catched by CarobProtector: ");
+static const wstring COPREFIX(L"ControllerException catched by CarobProtector:
");
+static const wstring CAPREFIX(L"CarobException catched by CarobProtector: ");
static const wstring UEPREFIX(L"UnexpectedException catched by CarobProtector:
");
+static const wstring NEXTPREFIX(L" next exception :
");
static void cerrStackTrace(const wstring& prefix, const CarobException& cex)
{
+ wcerr << prefix << "SQL state: " << cex.getSQLState() << endl;
+ wcerr << prefix << "remote stack: " << endl;
const StackTrace& st = cex.getStackTrace();
for (StackTrace::const_iterator s = st.begin(); s != st.end(); s++)
- std::wcerr << prefix << " : " // TODO: need a toString() method
here
+ std::wcerr << prefix // TODO: need a toString() method here
<< s->declaringClass << ":" << s->methodName << "(...)" <<
std::endl;;
}
@@ -50,55 +54,69 @@
#endif
}
+static void cerrCarobExceptionChain(const wstring& prefix, const
CarobException& ce)
+{
+ cerrBackTrace(prefix, ce);
+ cerrStackTrace(prefix, ce);
+
+ const CarobException* nextex_p = &ce;
+ while ((nextex_p = nextex_p->getNext()) != NULL) {
+ wcerr << " Next CarobException" << endl;
+ cerrStackTrace(NEXTPREFIX, *nextex_p);
+ }
+}
+
+
/** This class is a quick & dirty (but working & useful) sketch of a
* generic CarobException catcher for CPPUnit */
class CarobProtector : public CppUnit::Protector
{
+ void reportCppUnitError(const CppUnit::ProtectorContext &context,
+ const string& prefix, const CarobException& ce)
+ {
+ wstring sqlState = ce.getSQLState();
+ reportError( context, CppUnit::Message(prefix
+ + toString(ce.description())
+ + toString(sqlState)));
+ }
+
bool protect( const CppUnit::Functor &functor,
const CppUnit::ProtectorContext &context )
-
{
try {
return functor();
}
catch (const BackendException& be)
{
-#if 1
// log
- logError(L"fctname", L"BackendException "+be.description());
- cerrBackTrace(BEPREFIX, be);
- wcerr << BEPREFIX << "state: " << be.getSQLState() << endl;
- wcerr << BEPREFIX << "remote stack: " << endl;
-
- cerrStackTrace(BEPREFIX, be);
- const CarobException* nextex_p = &be;
- while ((nextex_p = nextex_p->getNext()) != NULL) {
- wcerr << " Stack of next CarobException" << endl;
- cerrStackTrace(CEPREFIX, *nextex_p);
- }
-#endif
+ cerrCarobExceptionChain(BEPREFIX, be);
// CPPunit report
- string exmsg;
- wstring sqlState = be.getSQLState();
- reportError( context, CppUnit::Message("BackendException state: " +
toString(sqlState)));
-
+ reportCppUnitError(context, "BackendException:", be);
+ }
+ catch (const ControllerException& ce)
+ {
+ // log
+ cerrCarobExceptionChain(COPREFIX, ce);
+ // CPPunit report
+ reportCppUnitError(context, "ControllerException:", ce);
}
catch (const UnexpectedException& ue)
{
- logError(L"fctName", L"Catched unexpected exception");
- // TODO
- cerrBackTrace(UEPREFIX, ue);
- reportError( context, CppUnit::Message("Unexp excp") );
+ // log
+ cerrCarobExceptionChain(UEPREFIX, ue);
+ // CPPunit report
+ reportCppUnitError(context, "UnexpectedException:", ue);
}
+ // catch all other CarobExceptions
catch (const CarobException& ce)
{
- logError(L"fctName", L"Catched carob exception");
- // TODO
- cerrBackTrace(CEPREFIX, ce);
- reportError( context, CppUnit::Message("carob excp") );
+ // log
+ cerrCarobExceptionChain(CAPREFIX, ce);
+ // CPPunit report
+ reportCppUnitError(context, "CarobException:", ce);
}
return false; // meaning: failed?
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits