Made Aegilib::Exception derive from std::exception.

Originally committed to SVN as r2039.
This commit is contained in:
Rodrigo Braz Monteiro 2008-03-13 07:28:30 +00:00
parent dff23e8cd3
commit bcb87d1ebd
3 changed files with 9 additions and 5 deletions

View file

@ -36,11 +36,12 @@
#pragma once #pragma once
#include "aegistring.h" #include "aegistring.h"
#include <exception>
namespace Aegilib { namespace Aegilib {
// Exception class // Exception class
class Exception { class Exception : public std::exception {
public: public:
enum ExceptionList { enum ExceptionList {
Unknown, Unknown,
@ -55,10 +56,11 @@ namespace Aegilib {
Exception(ExceptionList code); Exception(ExceptionList code);
String GetMessage(); String GetMessage() const { return GetMessage(code); }
int GetCode(); int GetCode();
private: private:
static String GetMessage(int code);
ExceptionList code; ExceptionList code;
}; };

View file

@ -40,6 +40,7 @@ using namespace Aegilib;
/////////////// ///////////////
// Constructor // Constructor
Exception::Exception(ExceptionList _code) Exception::Exception(ExceptionList _code)
: std::exception(GetMessage(_code).mb_str(wxConvLocal))
{ {
code = _code; code = _code;
} }
@ -47,7 +48,7 @@ Exception::Exception(ExceptionList _code)
////////////////////// //////////////////////
// Get message string // Get message string
String Exception::GetMessage() String Exception::GetMessage(int code)
{ {
switch (code) { switch (code) {
case Unknown: return L"Unknown."; case Unknown: return L"Unknown.";

View file

@ -60,6 +60,7 @@ int main () {
// Modify subtitles // Modify subtitles
cout << "Modifying file..."; cout << "Modifying file...";
// TODO
cout << "Done.\n"; cout << "Done.\n";
// Save subtitles // Save subtitles
@ -68,7 +69,7 @@ int main () {
cout << "Done.\n"; cout << "Done.\n";
} }
catch (Exception &e) { catch (std::exception &e) {
cout << "\n\nException: " << e.GetMessage().mb_str(wxConvUTF8) << endl << endl; cout << "\n\nException: " << e.what() << endl << endl;
} }
} }