Don't show stack traces for user errors.

Refs #5846
This commit is contained in:
Gunnar Beutner 2014-03-22 08:38:46 +01:00
parent c9590d5183
commit 3c067e9547
2 changed files with 32 additions and 25 deletions

View File

@ -38,28 +38,31 @@ void __cxa_throw(void *obj, void *pvtinfo, void (*dest)(void *))
void *thrown_ptr = obj;
const std::type_info *tinfo = static_cast<std::type_info *>(pvtinfo);
const std::type_info *boost_exc = &typeid(boost::exception);
const std::type_info *user_exc = &typeid(user_error);
/* Check if the exception is a pointer type. */
if (tinfo->__is_pointer_p())
thrown_ptr = *(void **)thrown_ptr;
if (!user_exc->__do_catch(tinfo, &thrown_ptr, 1)) {
#endif /* __APPLE__ */
StackTrace stack;
SetLastExceptionStack(stack);
StackTrace stack;
SetLastExceptionStack(stack);
ContextTrace context;
SetLastExceptionContext(context);
ContextTrace context;
SetLastExceptionContext(context);
#ifndef __APPLE__
/* Check if thrown_ptr inherits from boost::exception. */
if (boost_exc->__do_catch(tinfo, &thrown_ptr, 1)) {
boost::exception *ex = (boost::exception *)thrown_ptr;
/* Check if thrown_ptr inherits from boost::exception. */
if (boost_exc->__do_catch(tinfo, &thrown_ptr, 1)) {
boost::exception *ex = (boost::exception *)thrown_ptr;
if (boost::get_error_info<StackTraceErrorInfo>(*ex) == NULL)
*ex << StackTraceErrorInfo(stack);
if (boost::get_error_info<StackTraceErrorInfo>(*ex) == NULL)
*ex << StackTraceErrorInfo(stack);
if (boost::get_error_info<ContextTraceErrorInfo>(*ex) == NULL)
*ex << ContextTraceErrorInfo(context);
if (boost::get_error_info<ContextTraceErrorInfo>(*ex) == NULL)
*ex << ContextTraceErrorInfo(context);
}
}
#endif /* __APPLE__ */

View File

@ -39,6 +39,8 @@
namespace icinga
{
class I2_BASE_API user_error : virtual public std::exception, virtual public boost::exception { };
I2_BASE_API StackTrace *GetLastExceptionStack(void);
I2_BASE_API void SetLastExceptionStack(const StackTrace& trace);
@ -55,22 +57,24 @@ String DiagnosticInformation(const T& ex, StackTrace *stack = NULL, ContextTrace
result << boost::diagnostic_information(ex);
if (boost::get_error_info<StackTraceErrorInfo>(ex) == NULL) {
result << std::endl;
if (dynamic_cast<const user_error *>(&ex) == NULL) {
if (boost::get_error_info<StackTraceErrorInfo>(ex) == NULL) {
result << std::endl;
if (stack)
result << *stack;
else
result << *GetLastExceptionStack();
}
if (stack)
result << *stack;
else
result << *GetLastExceptionStack();
}
if (boost::get_error_info<ContextTraceErrorInfo>(ex) == NULL) {
result << std::endl;
if (boost::get_error_info<ContextTraceErrorInfo>(ex) == NULL) {
result << std::endl;
if (context)
result << *context;
else
result << *GetLastExceptionContext();
if (context)
result << *context;
else
result << *GetLastExceptionContext();
}
}
return result.str();