This file demonstrates how error management and handling is done in Zorba.
#include <iostream>
using namespace zorba;
bool
error_example_1(
Zorba* aZorba)
{
try {
std::cout << lQuery << std::endl;
std::cout << e << std::endl;
return true;
}
return false;
}
bool
error_example_2(
Zorba* aZorba)
{
try {
std::cout << e << std::endl;
return true;
}
return false;
}
{
public:
{
std::cerr << ze << std::endl;
else
}
{
std::cerr << xw << std::endl;
}
};
bool
error_example_3(
Zorba* aZorba)
{
MyDiagnosticHandler lHandler;
return true;
}
bool
error_example_4(
Zorba* aZorba)
{
MyDiagnosticHandler lHandler;
try {
lQuery->registerDiagnosticHandler(&lHandler);
std::cout << lQuery << std::endl;
std::cerr << e << std::endl;
return true;
}
return false;
}
bool
error_example_5(
Zorba* aZorba)
{
try {
XQuery_t lQuery = aZorba->
compileQuery(
"fn:error(fn:QName('http://www.w3.org/2005/xqt-errors', 'err:FOER0000'), 'a user error', 1 to 10)");
std::cout << lQuery << std::endl;
UserException::error_object_type::const_iterator
it;
for ( it = error.begin(); it != error.end(); ++
it ) {
std::cout << it->getStringValue() << std::endl;
}
return true;
std::cerr << ze << std::endl;
return false;
}
return false;
}
bool
error_example_6(
Zorba* aZorba)
{
try {
"http://www.zorba-xquery.com/options/warnings", "", "error");
lCtx->declareOption(lQName, "ZWST0003");
std::ostringstream s;
s << "declare namespace z = 'http://www.zorba-xquery.com/annotations';" << std::endl
<< "declare %z:sequential function local:foo() { 1 };" << std::endl
<< "local:foo()" << std::endl;
std::cout << lQuery << std::endl;
return true;
std::cerr << ze << std::endl;
return false;
}
return false;
}
bool
error_example_7(
Zorba* aZorba)
{
try {
std::ostringstream s;
s << "declare function local:test() { fn:error() };" << std::endl
<< "local:test()" << std::endl;
std::cout << lQuery << std::endl;
std::cerr << "=== Error XML + Stacktrace ===" << std::endl;
<< ze
<< std::endl;
std::cerr << "=== Error Text + Stacktrace ===" << std::endl;
<< ze
<< std::endl;
return true;
}
return false;
}
int
errors(int argc, char* argv[])
{
bool res = false;
std::cout << "executing example 1" << std::endl;
res = error_example_1(lZorba);
if (!res) return 1;
std::cout << std::endl;
std::cout << "executing example 2" << std::endl;
res = error_example_2(lZorba);
if (!res) return 1;
std::cout << std::endl;
std::cout << "executing example 3" << std::endl;
res = error_example_3(lZorba);
if (!res) return 1;
std::cout << std::endl;
std::cout << "executing example 4" << std::endl;
res = error_example_4(lZorba);
if (!res) return 1;
std::cout << std::endl;
std::cout << "executing example 5" << std::endl;
res = error_example_5(lZorba);
if (!res) return 1;
std::cout << std::endl;
std::cout << "executing example 6" << std::endl;
res = error_example_6(lZorba);
if (!res) return 1;
std::cout << std::endl;
std::cout << "executing example 7" << std::endl;
res = error_example_7(lZorba);
if (!res) return 1;
std::cout << std::endl;
return 0;
}