| Index: src/plugin/PluginDebug.cpp |
| =================================================================== |
| --- a/src/plugin/PluginDebug.cpp |
| +++ b/src/plugin/PluginDebug.cpp |
| @@ -18,9 +18,83 @@ |
| #include "PluginStdAfx.h" |
| #include "PluginDebug.h" |
| +#include "Exception.h" |
| #include "PluginMutex.h" |
| #include "PluginSettings.h" |
| +#if (defined ENABLE_DEBUG_INFO) |
| +namespace { |
| + // VS 2012 does not have support for variadic templates, which would eliminate the need for an argument class. |
| + struct LogHandlersArguments |
| + { |
| + bool isEntryPoint; |
| + std::string name; |
| + }; |
| + |
| + std::string DefaultLogMessage(const LogHandlersArguments& x, const std::string &exceptionType) |
| + { |
| + std::string s = x.isEntryPoint ? "ENTRY POINT '" : "'"; |
| + s += x.name; |
| + s += "' caught default "; |
| + s += exceptionType; |
| + return s; |
| + } |
| + |
| + struct LogHandlers |
| + { |
| + static void Unknown(const LogHandlersArguments& args) |
| + { |
| + CPluginDebug::Debug(DefaultLogMessage(args, "Unknown exception")); |
| + } |
| + static void Exception(const std::exception& ex, LogHandlersArguments& args) |
| + { |
| + CPluginDebug::DebugOrdinaryException(ex, |
| + PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION, |
| + DefaultLogMessage(args, "std::exception")); |
| + } |
| + static void LogicError(const std::logic_error& ex, LogHandlersArguments& args) |
| + { |
| + CPluginDebug::DebugOrdinaryException(ex, |
| + PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION, |
| + DefaultLogMessage(args, "std::logic_error")); |
| + } |
| + static void RuntimeError(const std::runtime_error& ex, LogHandlersArguments& args) |
| + { |
| + CPluginDebug::DebugOrdinaryException(ex, |
| + PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION, |
| + DefaultLogMessage(args, "std::runtime_error")); |
| + } |
| + static void SystemError(const std::system_error& ex, LogHandlersArguments& args) |
| + { |
| + CPluginDebug::DebugSystemException(ex, |
| + PLUGIN_ERROR_ENTRY_POINT, PLUGIN_ERROR_ENTRY_POINT_CATCHALL_EXCEPTION, |
| + DefaultLogMessage(args, "std::std::system_error")); |
| + } |
| + }; |
| +} |
| +#endif |
| + |
| +void EntryPointExceptionDefault(const std::string& name) |
| +{ |
| +#if (defined ENABLE_DEBUG_INFO) |
| + // VS 2012 does not have support for brace initializer lists; otherwise this could be a single line |
| + LogHandlersArguments x; |
| + x.isEntryPoint = true; |
| + x.name = name; |
| + CatchAllVoid<LogHandlers>::Handler(x); |
| +#endif |
| +} |
| + |
| +void ExceptionDefault(const std::string& name) |
| +{ |
| +#if (defined ENABLE_DEBUG_INFO) |
| + LogHandlersArguments x; |
| + x.isEntryPoint = false; |
| + x.name = name; |
| + CatchAllVoid<LogHandlers>::Handler(x); |
| +#endif |
| +} |
| + |
| class CPluginDebugLock : public CPluginMutex |
| { |
| @@ -45,8 +119,14 @@ |
| void CPluginDebug::DebugSystemException(const std::system_error& ex, int errorId, int errorSubid, const std::string& description) |
| { |
| - std::string message = description + ", " + ex.code().message() + ", " + ex.what(); |
| - DEBUG_ERROR_LOG(ex.code().value(), errorId, errorSubid, message); |
| + std::string message = description + ", " + ex.code().message() + ", " + ex.what(); |
| + DEBUG_ERROR_LOG(ex.code().value(), errorId, errorSubid, message); |
| +} |
| + |
| +void CPluginDebug::DebugOrdinaryException(const std::exception& ex, int errorId, int errorSubid, const std::string& description) |
| +{ |
| + std::string message = description + ", " + ex.what(); |
| + DEBUG_ERROR_LOG(0, errorId, errorSubid, message); |
| } |
| #ifdef ENABLE_DEBUG_INFO |