|
Boost : |
From: Ruediger Berlich (ruediger.berlich_at_[hidden])
Date: 2007-05-20 15:21:30
Dear Andrey, dear all,
I was wondering whether it would make sense to extend the log library to an
exception framework. This, I believe, could be done with minimal effort.
In my opinion every exception should lead to a log message, as an exception
will usually represent the most extreme condition available in an
application.
One way of raising an exception is to stream the error messages to a sink,
in the following way:
int errorCode = 3;
myExceptionType exc;
exc << "An error occured: " << errorCode << raiseException;
Within myExceptionType, "void raiseException(void)" triggers
a "throw(*this)". The rest of the streaming functionality is already
implemented in your library.
Extending the log classes with this functionality could be done with just
an "operator<<(void (*val)" (void))" and adding a "what()" member function.
This would allow the simultaneous use of the log classes as an exception
framework. Error messages would automatically end up in the log files
specified by the user, and log-related clean-up (closing of log-files,
connections, ...) could be handled as part of the process of raising an
exception.
Not sure whether this is a pipe dream, hence no entry in the Wiki.
Best Regards (and have a nice Sunday evening),
Ruediger Berlich
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk