mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-17 07:13:27 +02:00
pass error diagnostic string to the parent
added class documentation
This commit is contained in:
parent
461de57265
commit
f712074b62
@ -45,6 +45,7 @@
|
|||||||
#include "Poco/Data/ODBC/Diagnostics.h"
|
#include "Poco/Data/ODBC/Diagnostics.h"
|
||||||
#include "Poco/Data/ODBC/Error.h"
|
#include "Poco/Data/ODBC/Error.h"
|
||||||
#include "Poco/Data/DataException.h"
|
#include "Poco/Data/DataException.h"
|
||||||
|
#include "Poco/Format.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
@ -62,76 +63,101 @@ template <class H, SQLSMALLINT handleType>
|
|||||||
class HandleException: public ODBCException
|
class HandleException: public ODBCException
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HandleException(const H& handle): _error(handle)
|
HandleException(const H& handle):
|
||||||
|
ODBCException(errorString(handle)),
|
||||||
|
_error(handle)
|
||||||
|
/// Creates HandleException
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleException(const H& handle, const std::string& msg):
|
HandleException(const H& handle, const std::string& msg):
|
||||||
ODBCException(msg),
|
ODBCException(msg, errorString(handle)),
|
||||||
_error(handle)
|
_error(handle)
|
||||||
|
/// Creates HandleException
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleException(const H& handle, const std::string& msg, const std::string& arg):
|
HandleException(const H& handle, const std::string& msg, const std::string& arg):
|
||||||
ODBCException(msg, arg),
|
ODBCException(msg, arg),
|
||||||
_error(handle)
|
_error(handle)
|
||||||
|
/// Creates HandleException
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleException(const H& handle, const std::string& msg, const Poco::Exception& exc):
|
HandleException(const H& handle, const std::string& msg, const Poco::Exception& exc):
|
||||||
ODBCException(msg, exc),
|
ODBCException(msg, exc),
|
||||||
_error(handle)
|
_error(handle)
|
||||||
|
/// Creates HandleException
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleException(const HandleException& exc):
|
HandleException(const HandleException& exc):
|
||||||
ODBCException(exc),
|
ODBCException(exc),
|
||||||
_error(exc._error)
|
_error(exc._error)
|
||||||
|
/// Creates HandleException
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~HandleException() throw()
|
~HandleException() throw()
|
||||||
|
/// Destroys HandleException
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleException& operator = (const HandleException& exc)
|
HandleException& operator = (const HandleException& exc)
|
||||||
|
/// Assignment operator
|
||||||
{
|
{
|
||||||
HandleException::operator = (exc);
|
HandleException::operator = (exc);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* name() const throw()
|
const char* name() const throw()
|
||||||
|
/// Returns the name of the exception
|
||||||
{
|
{
|
||||||
return "ODBC handle exception";
|
return "ODBC handle exception";
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* className() const throw()
|
const char* className() const throw()
|
||||||
|
/// Returns the HandleException class name.
|
||||||
{
|
{
|
||||||
return typeid(*this).name();
|
return typeid(*this).name();
|
||||||
}
|
}
|
||||||
|
|
||||||
Poco::Exception* clone() const
|
Poco::Exception* clone() const
|
||||||
|
/// Clones the HandleException
|
||||||
{
|
{
|
||||||
return new HandleException(*this);
|
return new HandleException(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rethrow() const
|
void rethrow() const
|
||||||
|
/// Re-throws the HandleException.
|
||||||
{
|
{
|
||||||
throw *this;
|
throw *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Diagnostics<H, handleType>& diagnostics()
|
const Diagnostics<H, handleType>& diagnostics()
|
||||||
|
/// Returns error diagnostics.
|
||||||
{
|
{
|
||||||
return _error.diagnostics();
|
return _error.diagnostics();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string toString() const
|
std::string toString() const
|
||||||
|
/// Returns the formatted error diagnostics for the handle.
|
||||||
|
/// Since it relies on the object being fully constructed at
|
||||||
|
/// the time of its usage, this function should not be used
|
||||||
|
/// by the constructor to pass diagnostic string to the parent.
|
||||||
{
|
{
|
||||||
std::stringstream os;
|
return Poco::format("ODBC Error: %s\n===================\n%s\n",
|
||||||
os << "ODBC Error: " << what() << std::endl
|
std::string(what()),
|
||||||
<< "===================" << std::endl
|
_error.toString());
|
||||||
<< _error.toString() << std::endl ;
|
}
|
||||||
return os.str();
|
|
||||||
|
static std::string errorString(const H& handle)
|
||||||
|
/// Returns the error diagnostics for the handle.
|
||||||
|
/// This function is used by the constructor to pass diagnostic
|
||||||
|
/// string to the parent. It can also be used as a "shortcut" to
|
||||||
|
/// error information during troubleshooting.
|
||||||
|
{
|
||||||
|
return Error<H, handleType>(handle).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user