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.
Merged error handling changes from 5.5.1.
- Loading branch information
Showing
59 changed files
with
3,381 additions
and
2,098 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -33,3 +33,4 @@ hmailserver/source/Server/hMailServer/Release/* | |
*.sdf | ||
*.opensdf | ||
*.ipch | ||
*.orig |
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
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
109 changes: 109 additions & 0 deletions
109
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,109 @@ | ||
// Copyright (c) 2010 Martin Knafve / hMailServer.com. | ||
// http://www.hmailserver.com | ||
|
||
#include "StdAfx.h" | ||
|
||
#include "ExceptionHandler.h" | ||
#include "../Util/ExceptionLogger.h" | ||
|
||
#include <boost/thread/thread.hpp> | ||
#include "../TCPIP/DisconnectedException.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) | ||
{ | ||
// if an error occurs when shutting down, we want to log it completely before | ||
// the shut down completes. | ||
boost::this_thread::disable_interruption shutdown_temporarily_disabled; | ||
|
||
LOG_DEBUG("Logging exception.."); | ||
|
||
ExceptionLogger::Log(dwExpCode, pExp); | ||
|
||
LOG_DEBUG("Completed logging of exception..."); | ||
|
||
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 (boost::thread_interrupted&) | ||
{ | ||
// shutting down | ||
} | ||
catch (DisconnectedException&) | ||
{ | ||
LOG_DEBUG("Connection was terminated - Client is disconnected."); | ||
} | ||
catch (boost::system::system_error& error) | ||
{ | ||
ErrorManager::Instance()->ReportError(ErrorManager::High, 4208, "ExceptionHandler::Run", GetExceptionText(descriptive_name), error); | ||
|
||
throw; | ||
} | ||
catch (std::exception& 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.