forked from hmailserver/hmailserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated exception handling. Introduced StackWalker to extract stack t…
…races rather than having catch spread throughout the code.
- Loading branch information
1 parent
2f62d3a
commit 8c3d8a3
Showing
39 changed files
with
4,476 additions
and
2,057 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
hmailserver/source/Server/Common/Application/ExceptionHandler.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright (c) 2010 Martin Knafve / hMailServer.com. | ||
// http://www.hmailserver.com | ||
|
||
#include "StdAfx.h" | ||
|
||
#include "ExceptionHandler.h" | ||
#include "../Util/StackLogger.h" | ||
|
||
|
||
#ifdef _DEBUG | ||
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) | ||
#define new DEBUG_NEW | ||
#endif | ||
|
||
namespace HM | ||
{ | ||
ExceptionHandler::ExceptionHandler(void) | ||
{ | ||
|
||
} | ||
|
||
LONG WINAPI ExceptionFilterWithLogging(EXCEPTION_POINTERS* pExp, DWORD dwExpCode) | ||
{ | ||
StackLogger::Log(dwExpCode, pExp->ContextRecord); | ||
|
||
return EXCEPTION_EXECUTE_HANDLER; | ||
} | ||
|
||
bool | ||
ExceptionHandler::Run(const String &descriptive_name, boost::function<void()>& func) | ||
{ | ||
__try | ||
{ | ||
RunWithStandardExceptions(descriptive_name, func); | ||
return true; | ||
} | ||
__except (ExceptionFilterWithLogging(GetExceptionInformation(), GetExceptionCode())) | ||
{ | ||
// this has been logged in the exception filter. | ||
return false; | ||
} | ||
} | ||
|
||
void | ||
ExceptionHandler::RunWithStandardExceptions(const String &descriptive_name, boost::function<void()>& func) | ||
{ | ||
try | ||
{ | ||
func(); | ||
} | ||
catch (thread_interrupted const&) | ||
{ | ||
// shutting down | ||
} | ||
catch (boost::system::system_error error) | ||
{ | ||
ErrorManager::Instance()->ReportError(ErrorManager::High, 4208, "ExceptionHandler::Run", GetExceptionText(descriptive_name), error); | ||
|
||
throw; | ||
} | ||
catch (std::exception const& error) | ||
{ | ||
String sErrorMessage = | ||
Formatter::Format("An error occured while executing '{0}'", descriptive_name); | ||
|
||
ErrorManager::Instance()->ReportError(ErrorManager::High, 4208, "ExceptionHandler::Run", GetExceptionText(descriptive_name), error); | ||
|
||
throw; | ||
} | ||
catch (...) | ||
{ | ||
String sErrorMessage = | ||
Formatter::Format("An error occured while executing '{0}'", descriptive_name); | ||
|
||
ErrorManager::Instance()->ReportError(ErrorManager::High, 4208, "ExceptionHandler::Run", GetExceptionText(descriptive_name)); | ||
|
||
throw; | ||
} | ||
} | ||
|
||
|
||
|
||
String | ||
ExceptionHandler::GetExceptionText(const String &descriptive_name) | ||
{ | ||
String sErrorMessage = | ||
Formatter::Format("An error occured while executing '{0}'", descriptive_name); | ||
|
||
return sErrorMessage; | ||
|
||
} | ||
|
||
|
||
} |
22 changes: 22 additions & 0 deletions
22
hmailserver/source/Server/Common/Application/ExceptionHandler.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) 2010 Martin Knafve / hMailServer.com. | ||
// http://www.hmailserver.com | ||
|
||
#pragma once | ||
|
||
namespace HM | ||
{ | ||
class ExceptionHandler | ||
{ | ||
public: | ||
ExceptionHandler(); | ||
|
||
static bool Run(const String &descriptive_name, boost::function<void()>& functionToRun); | ||
|
||
private: | ||
|
||
static void RunWithStandardExceptions(const String &descriptive_name, boost::function<void()>& functionToRun); | ||
|
||
static String GetExceptionText(const String &descriptive_name); | ||
|
||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ namespace HM | |
|
||
|
||
void WorkerFunc(); | ||
void WorkerFuncInternal(); | ||
|
||
void IndexMessages_(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.