Fixed issue 479

This commit is contained in:
Nick Bolton 2010-06-01 20:22:37 +00:00
parent 6278a8fb14
commit a2b79e062c
4 changed files with 59 additions and 15 deletions

View File

@ -20,6 +20,7 @@
#include "CApp.h"
#include "LogOutputters.h"
#include "CMSWindowsScreen.h"
#include "XSynergy.h"
#include <sstream>
#include <iostream>
@ -189,7 +190,7 @@ exitPause(int code)
int c = _getch();
}
exit(code);
throw XExitApp(code);
}
static

View File

@ -21,6 +21,7 @@
#include "XArch.h"
#include "CArchMiscWindows.h"
#include "LogOutputters.h"
#include "XSynergy.h"
#include <iostream>
#include <stdio.h>
@ -230,34 +231,31 @@ CApp::run(int argc, char** argv, CreateTaskBarReceiverFunc createTaskBarReceiver
// create an instance of log
CLOG;
// HACK: fail by default (saves us setting result in each catch)
int result = kExitFailed;
int result;
try {
result = ARCH->run(argc, argv, createTaskBarReceiver);
}
catch (XExitApp& e) {
LOG((CLOG_WARN "Forced exit: %s\n", e.what()));
}
catch (XBase& e) {
LOG((CLOG_CRIT "Uncaught exception: %s\n", e.what()));
result = kExitFailed;
LOG((CLOG_CRIT "Exception: %s\n", e.what()));
}
catch (XArch& e) {
LOG((CLOG_CRIT "Initialization failed: %s" BYE, e.what().c_str(), argsBase().m_pname));
result = kExitFailed;
LOG((CLOG_CRIT "Init failed: %s" BYE, e.what().c_str(), argsBase().m_pname));
}
catch (std::exception& e) {
LOG((CLOG_CRIT "Uncaught exception: %s\n", e.what()));
result = kExitFailed;
LOG((CLOG_CRIT "Exception: %s\n", e.what()));
}
catch (...) {
LOG((CLOG_CRIT "Uncaught exception: <unknown exception>\n"));
result = kExitFailed;
LOG((CLOG_CRIT "An unexpected exception occurred.\n"));
}
delete CLOG;
// not sure i like what's going on here; m_bye could call exit, but it also does
// some other stuff - if we don't return then we get compiler warning (and it's
// not good practice anyway), but the return will never get hit.
m_bye(result);
return result;
}

View File

@ -102,3 +102,28 @@ XUnknownClient::getWhat() const throw()
{
return format("XUnknownClient", "unknown client %{1}", m_name.c_str());
}
//
// XExitApp
//
XExitApp::XExitApp(int code) :
m_code(code)
{
// do nothing
}
int
XExitApp::getCode() const throw()
{
return m_code;
}
CString
XExitApp::getWhat() const throw()
{
return format(
"XExitApp", "exiting with code %{1}",
CStringUtil::print("%d", m_code).c_str());
}

View File

@ -102,4 +102,24 @@ private:
CString m_name;
};
//! Generic exit eception
/*!
Thrown when we want to abort, with the opportunity to clean up. This is a
little bit of a hack, but it's a better way of exiting, than just calling
exit(int).
*/
class XExitApp : public XSynergy {
public:
XExitApp(int code);
//! Get the exit code
int getCode() const throw();
protected:
virtual CString getWhat() const throw();
private:
int m_code;
};
#endif