Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/plugin/PluginDebug.cpp

Issue 5137721374801920: Issue #1173 - Default behavior for catch-all blocks
Patch Set: Address comments Created March 6, 2015, 5:26 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/plugin/PluginDebug.h ('k') | test/plugin/ExceptionTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/plugin/PluginDebug.cpp
===================================================================
--- a/src/plugin/PluginDebug.cpp
+++ b/src/plugin/PluginDebug.cpp
@@ -16,11 +16,84 @@
*/
#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(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(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(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(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 +118,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
« no previous file with comments | « src/plugin/PluginDebug.h ('k') | test/plugin/ExceptionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld