forked from mia/Aegisub
Made Athenasub::Exception print a stack trace.
Originally committed to SVN as r2471.
This commit is contained in:
parent
ac9bd6e0db
commit
ad4a9daf75
5 changed files with 58 additions and 38 deletions
|
@ -254,10 +254,6 @@
|
|||
RelativePath=".\src\exception.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\exception.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\fastbuffer.h"
|
||||
>
|
||||
|
|
|
@ -35,8 +35,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
//#include "athenastring.h"
|
||||
#include <string>
|
||||
#include "athenastring.h"
|
||||
#include <exception>
|
||||
|
||||
namespace Athenasub {
|
||||
|
@ -59,15 +58,13 @@ namespace Athenasub {
|
|||
TODO
|
||||
};
|
||||
|
||||
Exception(ExceptionList _code);
|
||||
Exception(ExceptionList _code,const char* file,const long line);
|
||||
Exception(ExceptionList code,String message="",const char* file=NULL,const long line=0);
|
||||
|
||||
//String GetMessageString() const { return String(what(),wxConvLocal); }
|
||||
int GetCode() { return code; }
|
||||
|
||||
private:
|
||||
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;
|
||||
};
|
||||
|
@ -76,8 +73,10 @@ namespace Athenasub {
|
|||
|
||||
#ifndef THROW_ATHENA_EXCEPTION
|
||||
#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
|
||||
#define THROW_ATHENA_EXCEPTION(code) throw Athenasub::Exception(code)
|
||||
#define THROW_ATHENA_EXCEPTION_MSG(code,message) throw Athenasub::Exception(code,message)
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -37,16 +37,32 @@
|
|||
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
|
||||
Exception::Exception(ExceptionList _code)
|
||||
: std::exception(GetMessageChar(_code).c_str())
|
||||
{
|
||||
code = _code;
|
||||
}
|
||||
|
||||
Exception::Exception(ExceptionList _code,const char* file,const long line)
|
||||
: std::exception(GetMessageFile(_code,file,line).c_str())
|
||||
Exception::Exception(ExceptionList _code,String message,const char* file,const long line)
|
||||
: std::exception(GetExceptionMessage(_code,message,file,line).c_str())
|
||||
{
|
||||
code = _code;
|
||||
}
|
||||
|
@ -76,12 +92,21 @@ std::string Exception::GetMessageChar(int code)
|
|||
|
||||
///////////////////////////////////////////
|
||||
// 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);
|
||||
str = str + " (" + file + ":";
|
||||
char buffer[16];
|
||||
_itoa_s(line,buffer,10);
|
||||
str = str + buffer + ")";
|
||||
|
||||
// Append macro filename
|
||||
if (file != NULL) {
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -66,17 +66,17 @@ namespace Athenasub {
|
|||
virtual bool HasMargins() const { return false; }
|
||||
|
||||
// Read accessors
|
||||
virtual const String& GetText() const { ThrowUnsupported(); return EmptyString(); }
|
||||
//virtual Time& GetStartTime() const { ThrowUnsupported(); return Time(); }
|
||||
//virtual Time& GetEndTime() const { ThrowUnsupported(); return Time(); }
|
||||
virtual int GetStartFrame() const { ThrowUnsupported(); return 0; }
|
||||
virtual int GetEndFrame() const { ThrowUnsupported(); return 0; }
|
||||
virtual bool IsComment() const { ThrowUnsupported(); return false; }
|
||||
virtual int GetLayer() const { ThrowUnsupported(); return 0; }
|
||||
virtual int GetMargin(int n) const { ThrowUnsupported(); return n; }
|
||||
virtual const String& GetStyle() const { ThrowUnsupported(); return EmptyString(); }
|
||||
virtual const String& GetActor() const { ThrowUnsupported(); return EmptyString(); }
|
||||
virtual const String& GetUserField() const { ThrowUnsupported(); return EmptyString(); }
|
||||
virtual const String& GetText() const { ThrowUnsupported(); }
|
||||
//virtual Time& GetStartTime() const { ThrowUnsupported(); }
|
||||
//virtual Time& GetEndTime() const { ThrowUnsupported(); }
|
||||
virtual int GetStartFrame() const { ThrowUnsupported(); }
|
||||
virtual int GetEndFrame() const { ThrowUnsupported(); }
|
||||
virtual bool IsComment() const { ThrowUnsupported(); }
|
||||
virtual int GetLayer() const { ThrowUnsupported(); }
|
||||
virtual int GetMargin(int n) const { (void) n; ThrowUnsupported(); }
|
||||
virtual const String& GetStyle() const { ThrowUnsupported(); }
|
||||
virtual const String& GetActor() const { ThrowUnsupported(); }
|
||||
virtual const String& GetUserField() const { ThrowUnsupported(); }
|
||||
|
||||
// Write accessors
|
||||
virtual void SetText(const String& text) { (void) text; ThrowUnsupported(); }
|
||||
|
|
|
@ -57,10 +57,10 @@ namespace Athenasub {
|
|||
|
||||
// Read accessors
|
||||
virtual String GetName() const=0;
|
||||
virtual String GetFontName() const { ThrowUnsupported(); return ""; }
|
||||
virtual float GetFontSize() const { ThrowUnsupported(); return 0.0f; }
|
||||
virtual String GetFontName() const { ThrowUnsupported(); }
|
||||
virtual float GetFontSize() const { ThrowUnsupported(); }
|
||||
//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 a new issue