From bcb87d1ebd08db41adb517afd6226df196d064f2 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Thu, 13 Mar 2008 07:28:30 +0000 Subject: [PATCH] Made Aegilib::Exception derive from std::exception. Originally committed to SVN as r2039. --- aegilib/include/aegilib/exception.h | 6 ++++-- aegilib/src/exception.cpp | 3 ++- aegilib/test/src/main.cpp | 5 +++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/aegilib/include/aegilib/exception.h b/aegilib/include/aegilib/exception.h index 7b11fe7f4..049fecdb5 100644 --- a/aegilib/include/aegilib/exception.h +++ b/aegilib/include/aegilib/exception.h @@ -36,11 +36,12 @@ #pragma once #include "aegistring.h" +#include namespace Aegilib { // Exception class - class Exception { + class Exception : public std::exception { public: enum ExceptionList { Unknown, @@ -55,10 +56,11 @@ namespace Aegilib { Exception(ExceptionList code); - String GetMessage(); + String GetMessage() const { return GetMessage(code); } int GetCode(); private: + static String GetMessage(int code); ExceptionList code; }; diff --git a/aegilib/src/exception.cpp b/aegilib/src/exception.cpp index 3b12f5fe8..a20ceb3ce 100644 --- a/aegilib/src/exception.cpp +++ b/aegilib/src/exception.cpp @@ -40,6 +40,7 @@ using namespace Aegilib; /////////////// // Constructor Exception::Exception(ExceptionList _code) +: std::exception(GetMessage(_code).mb_str(wxConvLocal)) { code = _code; } @@ -47,7 +48,7 @@ Exception::Exception(ExceptionList _code) ////////////////////// // Get message string -String Exception::GetMessage() +String Exception::GetMessage(int code) { switch (code) { case Unknown: return L"Unknown."; diff --git a/aegilib/test/src/main.cpp b/aegilib/test/src/main.cpp index 11518d6f3..ed5c1fb98 100644 --- a/aegilib/test/src/main.cpp +++ b/aegilib/test/src/main.cpp @@ -60,6 +60,7 @@ int main () { // Modify subtitles cout << "Modifying file..."; + // TODO cout << "Done.\n"; // Save subtitles @@ -68,7 +69,7 @@ int main () { cout << "Done.\n"; } - catch (Exception &e) { - cout << "\n\nException: " << e.GetMessage().mb_str(wxConvUTF8) << endl << endl; + catch (std::exception &e) { + cout << "\n\nException: " << e.what() << endl << endl; } }