Monitorable object & snapshot: Add information about exceptions thrown when updating metrics
In case an exception is thrown by a retrieveMetricValues
method, the following information will be stored in MonitorableObjectSnapshot
:
- The exception type
- The exception message
- The function, file and line from which the exception was thrown
- All of the above for a nested exception, in case one throws a new exception from a
catch
block and stores the previous exception as follows:
void my_internal_function()
{
MyException e("some message");
boost::throw_exception(MyException("blah"))\
<< ::boost::original_exception_type(&typeid(e))\
<< ::boost::throw_function(BOOST_CURRENT_FUNCTION)\
<< ::boost::throw_file(__FILE__)\
<< ::boost::throw_line((int)__LINE__);
}
void my_function()
{
try {
my_internal_function();
}
catch (boost::exception& e) {
const boost::exception_ptr lEPtr = boost::current_exception();
throw MyException2()\
<< ::boost::throw_function(BOOST_CURRENT_FUNCTION)\
<< ::boost::throw_file(__FILE__)\
<< ::boost::throw_line((int)__LINE__)\
<< (boost::errinfo_nested_exception(lEPtr));
}
}
Note: May need to update the SWATCH_THROW
macro in the future to be able to extract messages from nested exceptions correctly.