mirror of https://github.com/odrling/Aegisub
Made Athenasub::Exception print a stack trace.
Originally committed to SVN as r2471.
This commit is contained in:
parent
ac9bd6e0db
commit
ad4a9daf75
|
@ -254,10 +254,6 @@
|
||||||
RelativePath=".\src\exception.cpp"
|
RelativePath=".\src\exception.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath=".\include\aegilib\exception.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath=".\include\aegilib\fastbuffer.h"
|
RelativePath=".\include\aegilib\fastbuffer.h"
|
||||||
>
|
>
|
||||||
|
|
|
@ -35,8 +35,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
//#include "athenastring.h"
|
#include "athenastring.h"
|
||||||
#include <string>
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
||||||
namespace Athenasub {
|
namespace Athenasub {
|
||||||
|
@ -59,15 +58,13 @@ namespace Athenasub {
|
||||||
TODO
|
TODO
|
||||||
};
|
};
|
||||||
|
|
||||||
Exception(ExceptionList _code);
|
Exception(ExceptionList code,String message="",const char* file=NULL,const long line=0);
|
||||||
Exception(ExceptionList _code,const char* file,const long line);
|
|
||||||
|
|
||||||
//String GetMessageString() const { return String(what(),wxConvLocal); }
|
|
||||||
int GetCode() { return code; }
|
int GetCode() { return code; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::string GetMessageChar(int code);
|
static std::string GetMessageChar(int code);
|
||||||
static std::string GetMessageFile(int code,const char *file,long line);
|
static std::string GetExceptionMessage(int code,String message,const char *file,long line);
|
||||||
|
|
||||||
ExceptionList code;
|
ExceptionList code;
|
||||||
};
|
};
|
||||||
|
@ -76,8 +73,10 @@ namespace Athenasub {
|
||||||
|
|
||||||
#ifndef THROW_ATHENA_EXCEPTION
|
#ifndef THROW_ATHENA_EXCEPTION
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#define THROW_ATHENA_EXCEPTION(code) throw Athenasub::Exception(code,__FILE__,__LINE__)
|
#define THROW_ATHENA_EXCEPTION(code) throw Athenasub::Exception(code,"",__FILE__,__LINE__)
|
||||||
|
#define THROW_ATHENA_EXCEPTION_MSG(code,message) throw Athenasub::Exception(code,message,__FILE__,__LINE__)
|
||||||
#else
|
#else
|
||||||
#define THROW_ATHENA_EXCEPTION(code) throw Athenasub::Exception(code)
|
#define THROW_ATHENA_EXCEPTION(code) throw Athenasub::Exception(code)
|
||||||
|
#define THROW_ATHENA_EXCEPTION_MSG(code,message) throw Athenasub::Exception(code,message)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -37,16 +37,32 @@
|
||||||
using namespace Athenasub;
|
using namespace Athenasub;
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// Stack walker helper
|
||||||
|
#include <wx/stackwalk.h>
|
||||||
|
#include <wx/filename.h>
|
||||||
|
|
||||||
|
class Stack : public wxStackWalker {
|
||||||
|
std::string &str;
|
||||||
|
public:
|
||||||
|
Stack(std::string &dest) : str(dest) {}
|
||||||
|
|
||||||
|
void OnStackFrame(const wxStackFrame& frame)
|
||||||
|
{
|
||||||
|
wxString line = wxString::Format(_T("\n\t%03i - "),frame.GetLevel()) + frame.GetName();
|
||||||
|
if (frame.HasSourceLocation()) {
|
||||||
|
wxFileName fn(frame.GetFileName());
|
||||||
|
line += _T(" (") + fn.GetFullName() + wxString::Format(_T(":%i)"),frame.GetLine());
|
||||||
|
}
|
||||||
|
str += line.mb_str(wxConvUTF8);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
////////////////
|
////////////////
|
||||||
// Constructors
|
// Constructors
|
||||||
Exception::Exception(ExceptionList _code)
|
Exception::Exception(ExceptionList _code,String message,const char* file,const long line)
|
||||||
: std::exception(GetMessageChar(_code).c_str())
|
: std::exception(GetExceptionMessage(_code,message,file,line).c_str())
|
||||||
{
|
|
||||||
code = _code;
|
|
||||||
}
|
|
||||||
|
|
||||||
Exception::Exception(ExceptionList _code,const char* file,const long line)
|
|
||||||
: std::exception(GetMessageFile(_code,file,line).c_str())
|
|
||||||
{
|
{
|
||||||
code = _code;
|
code = _code;
|
||||||
}
|
}
|
||||||
|
@ -76,12 +92,21 @@ std::string Exception::GetMessageChar(int code)
|
||||||
|
|
||||||
///////////////////////////////////////////
|
///////////////////////////////////////////
|
||||||
// Get the message string for the filename
|
// Get the message string for the filename
|
||||||
std::string Exception::GetMessageFile(int code,const char *file,long line)
|
std::string Exception::GetExceptionMessage(int code,String message,const char *file,long line)
|
||||||
{
|
{
|
||||||
std::string str = GetMessageChar(code);
|
std::string str = GetMessageChar(code);
|
||||||
str = str + " (" + file + ":";
|
|
||||||
char buffer[16];
|
// Append macro filename
|
||||||
_itoa_s(line,buffer,10);
|
if (file != NULL) {
|
||||||
str = str + buffer + ")";
|
str = str + " (" + file + ":"; // Yes, there's an actual reason why that's not += (operator overloading)
|
||||||
|
char buffer[16];
|
||||||
|
_itoa_s(line,buffer,10);
|
||||||
|
str = str + buffer + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append stack trace
|
||||||
|
Stack stack(str);
|
||||||
|
stack.Walk(2);
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,17 +66,17 @@ namespace Athenasub {
|
||||||
virtual bool HasMargins() const { return false; }
|
virtual bool HasMargins() const { return false; }
|
||||||
|
|
||||||
// Read accessors
|
// Read accessors
|
||||||
virtual const String& GetText() const { ThrowUnsupported(); return EmptyString(); }
|
virtual const String& GetText() const { ThrowUnsupported(); }
|
||||||
//virtual Time& GetStartTime() const { ThrowUnsupported(); return Time(); }
|
//virtual Time& GetStartTime() const { ThrowUnsupported(); }
|
||||||
//virtual Time& GetEndTime() const { ThrowUnsupported(); return Time(); }
|
//virtual Time& GetEndTime() const { ThrowUnsupported(); }
|
||||||
virtual int GetStartFrame() const { ThrowUnsupported(); return 0; }
|
virtual int GetStartFrame() const { ThrowUnsupported(); }
|
||||||
virtual int GetEndFrame() const { ThrowUnsupported(); return 0; }
|
virtual int GetEndFrame() const { ThrowUnsupported(); }
|
||||||
virtual bool IsComment() const { ThrowUnsupported(); return false; }
|
virtual bool IsComment() const { ThrowUnsupported(); }
|
||||||
virtual int GetLayer() const { ThrowUnsupported(); return 0; }
|
virtual int GetLayer() const { ThrowUnsupported(); }
|
||||||
virtual int GetMargin(int n) const { ThrowUnsupported(); return n; }
|
virtual int GetMargin(int n) const { (void) n; ThrowUnsupported(); }
|
||||||
virtual const String& GetStyle() const { ThrowUnsupported(); return EmptyString(); }
|
virtual const String& GetStyle() const { ThrowUnsupported(); }
|
||||||
virtual const String& GetActor() const { ThrowUnsupported(); return EmptyString(); }
|
virtual const String& GetActor() const { ThrowUnsupported(); }
|
||||||
virtual const String& GetUserField() const { ThrowUnsupported(); return EmptyString(); }
|
virtual const String& GetUserField() const { ThrowUnsupported(); }
|
||||||
|
|
||||||
// Write accessors
|
// Write accessors
|
||||||
virtual void SetText(const String& text) { (void) text; ThrowUnsupported(); }
|
virtual void SetText(const String& text) { (void) text; ThrowUnsupported(); }
|
||||||
|
|
|
@ -57,10 +57,10 @@ namespace Athenasub {
|
||||||
|
|
||||||
// Read accessors
|
// Read accessors
|
||||||
virtual String GetName() const=0;
|
virtual String GetName() const=0;
|
||||||
virtual String GetFontName() const { ThrowUnsupported(); return ""; }
|
virtual String GetFontName() const { ThrowUnsupported(); }
|
||||||
virtual float GetFontSize() const { ThrowUnsupported(); return 0.0f; }
|
virtual float GetFontSize() const { ThrowUnsupported(); }
|
||||||
//virtual IColour& GetColour(int n) const { (void) n; ThrowUnsupported(); return Colour(); }
|
//virtual IColour& GetColour(int n) const { (void) n; ThrowUnsupported(); return Colour(); }
|
||||||
virtual int GetMargin(int n) const { (void) n; ThrowUnsupported(); return 0; }
|
virtual int GetMargin(int n) const { (void) n; ThrowUnsupported(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue