wxgui: retooled exception handling, should eliminate warnings in GCC and remove previous initialization ambiguities. (ended up being a nice code cleanup too, yay)

git-svn-id: http://pcsx2.googlecode.com/svn/branches/wxgui@1720 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
Jake.Stine 2009-09-01 00:43:28 +00:00
parent b0f454ef28
commit 25a31e3a03
18 changed files with 335 additions and 367 deletions

View File

@ -26,66 +26,108 @@ namespace Exception
{
//////////////////////////////////////////////////////////////////////////////////
// std::exception sucks, and isn't entirely cross-platform reliable in its implementation,
// so I made a replacement.
// so I made a replacement. The internal messages are non-const, which means that a
// catch clause can optionally modify them and then re-throw to a top-level handler.
//
// Note, this class is "abstract" which means you shouldn't use it directly like, ever.
// Use Exception::RuntimeError or Exception::LogicError instead for generic exceptions.
//
// Because exceptions are the (only!) really useful example of multiple inheritance,
// this class has only a trivial constructor, and must be manually initialized using
// InitBaseEx() or by individual member assignments. This is because C++ multiple inheritence
// is, by design, a lot of fail, especially when class initializers are mixed in.
//
// [TODO] : Add an InnerException component, and Clone() facility.
//
class BaseException
{
protected:
const wxString m_message_eng; // (untranslated) a "detailed" message of what disastrous thing has occurred!
const wxString m_message; // (translated) a "detailed" message of what disastrous thing has occurred!
const wxString m_stacktrace; // contains the stack trace string dump (unimplemented)
wxString m_message_diag; // (untranslated) a "detailed" message of what disastrous thing has occurred!
wxString m_message_user; // (translated) a "detailed" message of what disastrous thing has occurred!
wxString m_stacktrace; // contains the stack trace string dump (unimplemented)
public:
virtual ~BaseException() throw()=0; // the =0; syntax forces this class into "abstract" mode.
/*
// copy construct
BaseException( const BaseException& src ) :
m_message_eng( src.m_message_eng ),
m_message( src.m_message ),
m_stacktrace( src.m_stacktrace ) { }
m_message_diag( src.m_message_diag ),
m_message_user( src.m_message_user ),
m_stacktrace( src.m_stacktrace )
{ }
// Contruction using two pre-formatted pre-translated messages
BaseException( const wxString& msg_eng, const wxString& msg_xlt );
// trivial constructor, to appease the C++ multiple virtual inheritence gods. (CMVIGs!)
BaseException() {}*/
// Construction using one translation key.
explicit BaseException( const char* msg_eng );
const wxString& DiagMsg() const { return m_message_diag; }
const wxString& UserMsg() const { return m_message_user; }
wxString& DiagMsg() { return m_message_diag; }
wxString& UserMsg() { return m_message_user; }
// Returns a message suitable for diagnostic / logging purposes.
// This message is always in english, and includes a full stack trace.
virtual wxString LogMessage() const;
// This message is always in English, and includes a full stack trace.
virtual wxString FormatDiagnosticMessage() const;
// Returns a message suitable for end-user display.
// This message is usually meant for display in a user popup or such.
virtual wxString DisplayMessage() const { return m_message; }
virtual wxString FormatDisplayMessage() const { return m_message_user; }
protected:
// Construction using two pre-formatted pre-translated messages
void InitBaseEx( const wxString& msg_eng, const wxString& msg_xlt );
// Construction using one translation key.
void InitBaseEx( const char* msg_eng );
};
//////////////////////////////////////////////////////////////////////////////////////////
// Ps2Generic
// This class is used as a base exception for things tossed by PS2 cpus (EE, IOP, etc).
// Translation Note: These exceptions are never translated, except to issue a general
// error message to the user (which is specified below).
//
// Implementation note: does not derive from BaseException, so that we can use different
// catch block hierarchies to handle them (if needed).
//
// Translation Note: Currently these exceptions are never translated. English/diagnostic
// format only. :)
//
class Ps2Generic
{
protected:
const wxString m_message_eng; // (untranslated) a "detailed" message of what disastrous thing has occurred!
wxString m_message; // a "detailed" message of what disastrous thing has occurred!
public:
virtual ~Ps2Generic() throw() {}
explicit Ps2Generic( const char* msg ) :
m_message_eng( wxString::FromUTF8( msg ) ) { }
explicit Ps2Generic( const wxString& msg=L"Ps2/MIPS cpu caused a general exception" ) :
m_message_eng( msg ) { }
virtual u32 GetPc() const=0;
virtual bool IsDelaySlot() const=0;
virtual wxString Message() const { return m_message_eng; }
virtual wxString Message() const { return m_message; }
};
// Some helper macros for defining the standard constructors of internationalized constructors
// Parameters:
// classname - Yeah, the name of this class being defined. :)
//
// defmsg - default message (in english), which will be used for both english and i18n messages.
// The text string will be passed through the translator, so if it's int he gettext database
// it will be optionally translated.
//
#define DEFINE_EXCEPTION_COPYTORS( classname ) \
virtual ~classname() throw() {}
#define DEFINE_RUNTIME_EXCEPTION( classname, defmsg ) \
DEFINE_EXCEPTION_COPYTORS( classname ) \
\
explicit classname( const char* msg=defmsg ) { BaseException::InitBaseEx( msg ); } \
explicit classname( const wxString& msg_eng, const wxString& msg_xlt ) { BaseException::InitBaseEx( msg_eng, msg_xlt); }
#define DEFINE_LOGIC_EXCEPTION( classname, defmsg ) \
DEFINE_EXCEPTION_COPYTORS( classname ) \
\
explicit classname( const char* msg=defmsg ) { BaseException::InitBaseEx( msg ); } \
explicit classname( const wxString& msg_eng ) { BaseException::InitBaseEx( msg_eng, wxEmptyString ); }
// ---------------------------------------------------------------------------------------
// Generalized Exceptions: RuntimeError / LogicError / AssertionFailure
// ---------------------------------------------------------------------------------------
@ -93,43 +135,15 @@ namespace Exception
class RuntimeError : public virtual BaseException
{
public:
virtual ~RuntimeError() throw() {}
RuntimeError( const RuntimeError& src ) : BaseException( src ) {}
explicit RuntimeError( const char* msg=wxLt("An unhandled runtime error has occurred, somewhere in the depths of Pcsx2's cluttered brain-matter.") ) :
BaseException( msg ) { }
explicit RuntimeError( const wxString& msg_eng, const wxString& msg_xlt ) :
BaseException( msg_eng, msg_xlt ) { }
DEFINE_RUNTIME_EXCEPTION( RuntimeError, wxLt("An unhandled runtime error has occurred, somewhere in the depths of Pcsx2's cluttered brain-matter.") )
};
// LogicErrors do not need translated versions, since they are typically obscure, and the
// user wouldn't benefit from being able to understand them anyway. :)
class LogicError : public virtual BaseException
{
public:
virtual ~LogicError() throw() {}
LogicError( const LogicError& src ) : BaseException( src ) {}
explicit LogicError( const char* msg=wxLt("An unhandled logic error has occurred.") ) :
BaseException( msg ) { }
explicit LogicError( const wxString& msg_eng, const wxString& msg_xlt ) :
BaseException( msg_eng, msg_xlt ) { }
};
class AssertionFailure : public virtual LogicError
{
public:
explicit AssertionFailure( const char* msg=wxLt("Assertion Failure") ) :
LogicError( msg )
, BaseException( msg ) {}
explicit AssertionFailure( const wxString& msg_eng, const wxString& msg_xlt ) :
LogicError( msg_eng, msg_xlt )
, BaseException( msg_eng, msg_xlt ) {}
virtual ~AssertionFailure() throw() {}
DEFINE_LOGIC_EXCEPTION( LogicError, wxLt("An unhandled logic error has occurred.") )
};
// ---------------------------------------------------------------------------------------
@ -139,14 +153,7 @@ namespace Exception
class OutOfMemory : public virtual RuntimeError
{
public:
virtual ~OutOfMemory() throw() {}
explicit OutOfMemory( const char* msg=wxLt("Out of memory") ) :
RuntimeError( msg )
, BaseException( msg ) {}
explicit OutOfMemory( const wxString& msg_eng, const wxString& msg_xlt=_("Out of memory") ) :
RuntimeError( msg_eng, msg_xlt )
, BaseException( msg_eng, msg_xlt ) {}
DEFINE_RUNTIME_EXCEPTION( OutOfMemory, wxLt("Out of Memory") )
};
// This exception thrown any time an operation is attempted when an object
@ -155,14 +162,7 @@ namespace Exception
class InvalidOperation : public virtual LogicError
{
public:
virtual ~InvalidOperation() throw() {}
explicit InvalidOperation( const char* msg="Attempted method call is invalid for the current object or program state." ) :
LogicError( msg )
, BaseException( msg ) {}
explicit InvalidOperation( const wxString& msg_eng, const wxString& msg_xlt ) :
LogicError( msg_eng, msg_xlt )
, BaseException( msg_eng, msg_xlt ) {}
DEFINE_LOGIC_EXCEPTION( InvalidOperation, "Attempted method call is invalid for the current object or program state." )
};
// This exception thrown any time an operation is attempted when an object
@ -171,46 +171,39 @@ namespace Exception
class InvalidArgument : public virtual LogicError
{
public:
virtual ~InvalidArgument() throw() {}
explicit InvalidArgument( const char* msg="Invalid argument passed to a function." ) :
LogicError( msg )
, BaseException( msg )
{
// assertions make debugging easier sometimes. :)
wxASSERT_MSG_A( false, msg );
}
DEFINE_LOGIC_EXCEPTION( InvalidArgument, "Invalid argument passed to a function." )
};
// Keep those array indexers in bounds when using the SafeArray type, or you'll be
// seeing these.
//
class IndexBoundsFault : public virtual AssertionFailure
class IndexBoundsFault : public virtual LogicError
{
public:
const wxString ArrayName;
const int ArrayLength;
const int BadIndex;
wxString ArrayName;
int ArrayLength;
int BadIndex;
public:
virtual ~IndexBoundsFault() throw() {}
explicit IndexBoundsFault( const wxString& objname, int index, int arrsize ) :
AssertionFailure( "Index is outside the bounds of an array." ),
ArrayName( objname ),
ArrayLength( arrsize ),
BadIndex( index )
, BaseException( "Index is outside the bounds of an array." ) {}
DEFINE_EXCEPTION_COPYTORS( IndexBoundsFault )
virtual wxString LogMessage() const;
virtual wxString DisplayMessage() const;
IndexBoundsFault( const wxString& objname, int index, int arrsize )
{
BaseException::InitBaseEx( "Index is outside the bounds of an array." );
ArrayName = objname;
ArrayLength = arrsize;
BadIndex = index;
}
virtual wxString FormatDiagnosticMessage() const;
virtual wxString FormatDisplayMessage() const;
};
class ParseError : public RuntimeError
{
public:
virtual ~ParseError() throw() {}
explicit ParseError( const char* msg="Parse error" ) :
RuntimeError( msg )
, BaseException( msg ) {}
DEFINE_RUNTIME_EXCEPTION( ParseError, "Parse error" );
};
// ---------------------------------------------------------------------------------------
@ -221,19 +214,13 @@ namespace Exception
class HardwareDeficiency : public virtual RuntimeError
{
public:
explicit HardwareDeficiency( const char* msg=wxLt("Your machine's hardware is incapable of running Pcsx2. Sorry dood.") ) :
RuntimeError( msg )
, BaseException( msg ) {}
virtual ~HardwareDeficiency() throw() {}
DEFINE_RUNTIME_EXCEPTION( HardwareDeficiency, wxLt("Your machine's hardware is incapable of running Pcsx2. Sorry dood.") );
};
class ThreadCreationError : public virtual RuntimeError
{
public:
virtual ~ThreadCreationError() throw() {}
explicit ThreadCreationError( const char* msg="Thread could not be created." ) :
RuntimeError( msg )
, BaseException( msg ) {}
DEFINE_RUNTIME_EXCEPTION( ThreadCreationError, wxLt("Thread could not be created.") );
};
// ---------------------------------------------------------------------------------------
@ -241,6 +228,40 @@ namespace Exception
// Stream / BadStream / CreateStream / FileNotFound / AccessDenied / EndOfStream
// ---------------------------------------------------------------------------------------
#define DEFINE_STREAM_EXCEPTION( classname, defmsg ) \
DEFINE_EXCEPTION_COPYTORS( classname ) \
\
explicit classname( const wxString& objname=wxString(), const char* msg=defmsg ) \
{ \
BaseException::InitBaseEx( msg ); \
StreamName = objname; \
} \
explicit classname( const wxString& objname, const wxString& msg_eng, const wxString& msg_xlt ) \
{ \
BaseException::InitBaseEx( msg_eng, msg_xlt ); \
StreamName = objname; \
} \
explicit classname( const char* objname, const char* msg=defmsg ) \
{ \
BaseException::InitBaseEx( msg ); \
StreamName = wxString::FromUTF8( objname ); \
} \
explicit classname( const char* objname, const wxString& msg_eng, const wxString& msg_xlt ) \
{ \
BaseException::InitBaseEx( msg_eng, msg_xlt ); \
StreamName = wxString::FromUTF8( objname ); \
} \
explicit classname( const char* objname, const wxString& msg_eng ) \
{ \
BaseException::InitBaseEx( msg_eng, msg_eng ); \
StreamName = wxString::FromUTF8( objname ); \
} \
explicit classname( const wxString& objname, const wxString& msg_eng ) \
{ \
BaseException::InitBaseEx( msg_eng, msg_eng ); \
StreamName = objname; \
}
// Generic stream error. Contains the name of the stream and a message.
// This exception is usually thrown via derived classes, except in the (rare) case of a
// generic / unknown error.
@ -250,29 +271,11 @@ namespace Exception
public:
wxString StreamName; // name of the stream (if applicable)
virtual ~Stream() throw() {}
public:
DEFINE_STREAM_EXCEPTION( Stream, "General file operation error." )
// copy construct!
Stream( const Stream& src ) :
RuntimeError( src )
, BaseException( src )
, StreamName( src.StreamName ) {}
explicit Stream(
const wxString& objname=wxString(),
const char* msg="General file operation error" // general error while accessing or operating on a file or stream
) :
RuntimeError( msg )
, BaseException( msg )
, StreamName( objname ) {}
explicit Stream( const wxString& objname, const wxString& msg_eng, const wxString& msg_xlt=_("General file operation error") ) :
RuntimeError( msg_eng, msg_xlt )
, BaseException( msg_eng, msg_xlt )
, StreamName( objname ) {}
virtual wxString LogMessage() const;
virtual wxString DisplayMessage() const;
virtual wxString FormatDiagnosticMessage() const;
virtual wxString FormatDisplayMessage() const;
};
// A generic base error class for bad streams -- corrupted data, sudden closures, loss of
@ -282,17 +285,7 @@ namespace Exception
class BadStream : public virtual Stream
{
public:
virtual ~BadStream() throw() {}
explicit BadStream(
const wxString& objname=wxString(),
const char* msg=wxLt("File data is corrupted or incomplete, or the stream connection closed unexpectedly")
) :
Stream( objname, msg )
, BaseException( msg ) {}
explicit BadStream( const wxString& objname, const wxString& msg_eng, const wxString& msg_xlt ) :
Stream( objname, msg_eng, msg_xlt )
, BaseException( msg_eng, msg_xlt ) {}
DEFINE_STREAM_EXCEPTION( BadStream, wxLt("File data is corrupted or incomplete, or the stream connection closed unexpectedly") )
};
// A generic exception for odd-ball stream creation errors.
@ -300,24 +293,7 @@ namespace Exception
class CreateStream : public virtual Stream
{
public:
virtual ~CreateStream() throw() {}
explicit CreateStream(
const char* objname,
const char* msg=wxLt("File could not be created or opened") ) :
Stream( wxString::FromAscii( objname ), msg )
, BaseException( msg ) {}
explicit CreateStream(
const wxString& objname=wxString(),
const char* msg=wxLt("File could not be created or opened") ) :
Stream( objname, msg )
, BaseException( msg ) {}
explicit CreateStream(
const wxString& objname, const wxString& msg_eng, const wxString& msg_xlt ) :
Stream( objname, msg_eng, msg_xlt )
, BaseException( msg_eng, msg_xlt ) {}
DEFINE_STREAM_EXCEPTION( CreateStream, wxLt("File could not be created or opened") )
};
// Exception thrown when an attempt to open a non-existent file is made.
@ -326,30 +302,13 @@ namespace Exception
class FileNotFound : public virtual CreateStream
{
public:
virtual ~FileNotFound() throw() {}
explicit FileNotFound(
const wxString& objname=wxString(),
const char* msg="File not found" )
:
CreateStream( objname, msg )
, BaseException( msg ) {}
explicit FileNotFound( const wxString& objname, const wxString& msg_eng, const wxString& msg_xlt ) :
CreateStream( objname, msg_eng, msg_xlt )
, BaseException( msg_eng, msg_xlt ) {}
DEFINE_STREAM_EXCEPTION( FileNotFound, wxLt("File not found") )
};
class AccessDenied : public virtual CreateStream
{
public:
virtual ~AccessDenied() throw() {}
explicit AccessDenied(
const wxString& objname=wxString(),
const char* msg="Permission denied to file" )
:
CreateStream( objname, msg )
, BaseException( msg ) {}
DEFINE_STREAM_EXCEPTION( AccessDenied, wxLt("Permission denied to file") )
};
// EndOfStream can be used either as an error, or used just as a shortcut for manual
@ -358,10 +317,7 @@ namespace Exception
class EndOfStream : public virtual Stream
{
public:
virtual ~EndOfStream() throw() {}
explicit EndOfStream( const wxString& objname, const char* msg=wxLt("Unexpected end of file") ) :
Stream( objname, msg )
, BaseException( msg ) {}
DEFINE_STREAM_EXCEPTION( EndOfStream, wxLt("Unexpected end of file") );
};
// ---------------------------------------------------------------------------------------
@ -375,36 +331,32 @@ namespace Exception
class BadSavedState : public virtual BadStream
{
public:
virtual ~BadSavedState() throw() {}
explicit BadSavedState(
const wxString& objname=wxString(),
const char* msg="Savestate data is corrupted" ) : // or incomplete
BadStream( objname, msg )
, BaseException( msg ) {}
DEFINE_STREAM_EXCEPTION( BadSavedState, wxLt("Savestate data is corrupted or incomplete") )
};
// Exception thrown by SaveState class when a critical plugin or gzread
// Exception thrown by SaveState class when a plugin returns an error during state
// load or save.
//
class FreezePluginFailure : public virtual RuntimeError
{
public:
wxString plugin_name; // name of the plugin
wxString freeze_action;
wxString PluginName; // name of the plugin
wxString FreezeAction;
virtual ~FreezePluginFailure() throw() {}
explicit FreezePluginFailure( const char* plugin, const char* action,
const wxString& msg_xlt=_("Plugin error occurred while loading/saving state") )
:
RuntimeError( wxEmptyString, msg_xlt ) // LogMessage / DisplayMessage build their own messages
, BaseException( wxEmptyString, msg_xlt )
, plugin_name( wxString::FromAscii(plugin) )
, freeze_action( wxString::FromAscii(action) ) {}
public:
DEFINE_EXCEPTION_COPYTORS( FreezePluginFailure )
virtual wxString LogMessage() const;
virtual wxString DisplayMessage() const;
explicit FreezePluginFailure( const char* plugin, const char* action )
{
PluginName = wxString::FromUTF8( plugin );
FreezeAction = wxString::FromUTF8( action );
}
virtual wxString FormatDiagnosticMessage() const;
virtual wxString FormatDisplayMessage() const;
};
// A recoverable exception thrown when the savestate being loaded isn't supported.
// thrown when the savestate being loaded isn't supported.
//
class UnsupportedStateVersion : public virtual BadSavedState
{
@ -412,14 +364,16 @@ namespace Exception
u32 Version; // version number of the unsupported state.
public:
virtual ~UnsupportedStateVersion() throw() {}
explicit UnsupportedStateVersion( int version, const wxString& objname=wxEmptyString ) :
BadSavedState( objname )
, BaseException( wxEmptyString, wxEmptyString )
, Version( version ) {}
DEFINE_EXCEPTION_COPYTORS( UnsupportedStateVersion )
virtual wxString LogMessage() const;
virtual wxString DisplayMessage() const;
explicit UnsupportedStateVersion( int version, const wxString& objname=wxEmptyString )
{
StreamName = objname;
Version = version;
}
virtual wxString FormatDiagnosticMessage() const;
virtual wxString FormatDisplayMessage() const;
};
// A recoverable exception thrown when the CRC of the savestate does not match the
@ -433,15 +387,16 @@ namespace Exception
u32 Crc_Cdvd;
public:
virtual ~StateCrcMismatch() throw() {}
explicit StateCrcMismatch( u32 crc_save, u32 crc_cdvd, const wxString& objname=wxEmptyString ) :
BadSavedState( objname )
, BaseException( wxEmptyString, wxEmptyString )
, Crc_Savestate( crc_save )
, Crc_Cdvd( crc_cdvd )
{}
DEFINE_EXCEPTION_COPYTORS( StateCrcMismatch )
virtual wxString LogMessage() const;
virtual wxString DisplayMessage() const;
explicit StateCrcMismatch( u32 crc_save, u32 crc_cdvd, const wxString& objname=wxEmptyString )
{
StreamName = objname;
Crc_Savestate = crc_save;
Crc_Cdvd = crc_cdvd;
}
virtual wxString FormatDiagnosticMessage() const;
virtual wxString FormatDisplayMessage() const;
};
}

View File

@ -154,7 +154,9 @@ public:
L"Out-of-memory on SafeArray block re-allocation.\n"
L"Old size: %d bytes, New size: %d bytes.",
m_size, newsize
)
),
// internationalized!
wxsFormat( _("Out of memory, trying to allocate %d bytes."), newsize )
);
}
m_size = newsize;
@ -304,7 +306,9 @@ public:
L"Out-of-memory on SafeList block re-allocation.\n"
L"Old size: %d bytes, New size: %d bytes",
m_allocsize, newalloc
)
),
wxsFormat( _("Out of memory, trying to allocate %d bytes."), newalloc )
);
}

View File

@ -31,15 +31,8 @@ namespace Exception
// thread's call stack. This exception is handled by the PCSX2 PersistentThread class. Threads
// not derived from that class will not handle this exception.
//
class ThreadTermination : public BaseException
class ThreadTermination
{
public:
virtual ~ThreadTermination() throw() {}
ThreadTermination( const ThreadTermination& src ) : BaseException( src ) {}
explicit ThreadTermination() :
BaseException( "Thread terminated" ) { }
};
}

View File

@ -35,11 +35,11 @@ namespace Exception
// ------------------------------------------------------------------------
BaseException::~BaseException() throw() {}
BaseException::BaseException( const wxString& msg_eng, const wxString& msg_xlt ) :
m_message_eng( msg_eng ),
m_message( msg_xlt ),
m_stacktrace( wxEmptyString ) // unsupported yet
void BaseException::InitBaseEx( const wxString& msg_eng, const wxString& msg_xlt )
{
m_message_diag = msg_eng;
m_message_user = msg_xlt;
// Linux/GCC exception handling is still suspect (this is likely to do with GCC more
// than linux), and fails to propagate exceptions up the stack from EErec code. This
// could likely be because of the EErec using EBP. So to ensure the user at least
@ -53,69 +53,69 @@ namespace Exception
// given message is assumed to be a translation key, and will be stored in translated
// and untranslated forms.
BaseException::BaseException( const char* msg_eng ) :
m_message_eng( GetEnglish( msg_eng ) ),
m_message( GetTranslation( msg_eng ) ),
m_stacktrace( wxEmptyString ) // unsupported yet
void BaseException::InitBaseEx( const char* msg_eng )
{
m_message_diag = GetEnglish( msg_eng );
m_message_user = GetTranslation( msg_eng );
#ifdef __LINUX__
//wxLogError( m_message_eng.c_str() );
//wxLogError( m_message_diag.c_str() );
Console::Error( msg_eng );
#endif
}
wxString BaseException::LogMessage() const
wxString BaseException::FormatDiagnosticMessage() const
{
return m_message_eng + L"\n\n" + m_stacktrace;
return m_message_diag + L"\n\n" + m_stacktrace;
}
// ------------------------------------------------------------------------
wxString Stream::LogMessage() const
wxString Stream::FormatDiagnosticMessage() const
{
return wxsFormat(
L"Stream exception: %s\n\tObject name: %s",
m_message_eng.c_str(), StreamName.c_str()
m_message_diag.c_str(), StreamName.c_str()
) + m_stacktrace;
}
wxString Stream::DisplayMessage() const
wxString Stream::FormatDisplayMessage() const
{
return m_message + L"\n\n" + StreamName;
return m_message_user + L"\n\n" + StreamName;
}
// ------------------------------------------------------------------------
wxString FreezePluginFailure::LogMessage() const
wxString FreezePluginFailure::FormatDiagnosticMessage() const
{
return wxsFormat(
L"%s plugin returned an error while %s the state.\n\n",
plugin_name.c_str(),
freeze_action.c_str()
PluginName.c_str(),
FreezeAction.c_str()
) + m_stacktrace;
}
wxString FreezePluginFailure::DisplayMessage() const
wxString FreezePluginFailure::FormatDisplayMessage() const
{
return m_message;
return m_message_user;
}
// ------------------------------------------------------------------------
wxString UnsupportedStateVersion::LogMessage() const
wxString UnsupportedStateVersion::FormatDiagnosticMessage() const
{
// Note: no stacktrace needed for this one...
return wxsFormat( L"Unknown or unsupported savestate version: 0x%x", Version );
}
wxString UnsupportedStateVersion::DisplayMessage() const
wxString UnsupportedStateVersion::FormatDisplayMessage() const
{
// m_message contains a recoverable savestate error which is helpful to the user.
// m_message_user contains a recoverable savestate error which is helpful to the user.
return wxsFormat(
m_message + L"\n\n" +
m_message_user + L"\n\n" +
wxsFormat( _("Cannot load savestate. It is of an unknown or unsupported version."), Version )
);
}
// ------------------------------------------------------------------------
wxString StateCrcMismatch::LogMessage() const
wxString StateCrcMismatch::FormatDiagnosticMessage() const
{
// Note: no stacktrace needed for this one...
return wxsFormat(
@ -125,10 +125,10 @@ namespace Exception
);
}
wxString StateCrcMismatch::DisplayMessage() const
wxString StateCrcMismatch::FormatDisplayMessage() const
{
return wxsFormat(
m_message + L"\n\n" +
m_message_user + L"\n\n" +
wxsFormat(
L"Savestate game/crc mismatch. Cdvd CRC: 0x%X Game CRC: 0x%X\n",
Crc_Savestate, Crc_Cdvd
@ -137,14 +137,14 @@ namespace Exception
}
// ------------------------------------------------------------------------
wxString IndexBoundsFault::LogMessage() const
wxString IndexBoundsFault::FormatDiagnosticMessage() const
{
return L"Index out of bounds on SafeArray: " + ArrayName +
wxsFormat( L"(index=%d, size=%d)", BadIndex, ArrayLength );
}
wxString IndexBoundsFault::DisplayMessage() const
wxString IndexBoundsFault::FormatDisplayMessage() const
{
return m_message;
return m_message_user;
}
}

View File

@ -82,7 +82,7 @@ DEVASSERT_INLINE void DevAssert( bool condition, const char* msg )
{
if( IsDevBuild && !condition )
{
throw Exception::AssertionFailure( msg );
throw Exception::LogicError( msg );
}
}

View File

@ -527,20 +527,22 @@ PluginManager *g_plugins = NULL;
//////////////////////////////////////////////////////////////////////////////////////////
Exception::InvalidPluginConfigured::InvalidPluginConfigured( const PluginsEnum_t& pid, const wxString& objname, const char* eng ) :
BadStream( objname, eng )
, PluginError( pid )
, BaseException( eng )
{}
Exception::InvalidPluginConfigured::InvalidPluginConfigured( PluginsEnum_t pid, const wxString& objname, const char* eng )
{
BaseException::InitBaseEx( eng );
StreamName = objname;
PluginId = pid;
}
Exception::InvalidPluginConfigured::InvalidPluginConfigured( const PluginsEnum_t& pid, const wxString& objname,
const wxString& eng_msg, const wxString& xlt_msg ) :
BadStream( objname, eng_msg, xlt_msg )
, PluginError( pid )
, BaseException( eng_msg, xlt_msg )
{}
Exception::InvalidPluginConfigured::InvalidPluginConfigured( PluginsEnum_t pid, const wxString& objname,
const wxString& eng_msg, const wxString& xlt_msg )
{
BaseException::InitBaseEx( eng_msg, xlt_msg );
StreamName = objname;
PluginId = pid;
}
wxString Exception::PluginFailure::LogMessage() const
wxString Exception::PluginFailure::FormatDiagnosticMessage() const
{
return wxsFormat(
L"%s plugin has encountered an error.\n\n",
@ -548,9 +550,9 @@ wxString Exception::PluginFailure::LogMessage() const
) + m_stacktrace;
}
wxString Exception::PluginFailure::DisplayMessage() const
wxString Exception::PluginFailure::FormatDisplayMessage() const
{
return wxsFormat( m_message, plugin_name.c_str() );
return wxsFormat( m_message_user, plugin_name.c_str() );
}
//////////////////////////////////////////////////////////////////////////////////////////

View File

@ -42,14 +42,15 @@ namespace Exception
class PluginError : public virtual RuntimeError
{
public:
const PluginsEnum_t PluginId;
PluginsEnum_t PluginId;
public:
PluginError( PluginsEnum_t pid ) :
RuntimeError( "Generic plugin error" )
, BaseException( "Generic plugin error" )
, PluginId( pid )
DEFINE_EXCEPTION_COPYTORS( PluginError )
PluginError() {}
PluginError( PluginsEnum_t pid, const char* msg="Generic plugin error" )
{
BaseException::InitBaseEx( msg );
PluginId = pid;
}
};
@ -58,25 +59,27 @@ namespace Exception
public:
wxString plugin_name; // name of the plugin
virtual ~PluginFailure() throw() {}
public:
DEFINE_EXCEPTION_COPYTORS( PluginFailure )
explicit PluginFailure( const char* plugin, const char* msg="%s plugin encountered a critical error" ) :
RuntimeError( msg )
, BaseException( msg )
, plugin_name( wxString::FromAscii(plugin) ) {}
explicit PluginFailure( const char* plugin, const char* msg="%s plugin encountered a critical error" )
{
BaseException::InitBaseEx( msg );
plugin_name = wxString::FromUTF8( plugin );
}
virtual wxString LogMessage() const;
virtual wxString DisplayMessage() const;
virtual wxString FormatDiagnosticMessage() const;
virtual wxString FormatDisplayMessage() const;
};
class InvalidPluginConfigured : public virtual PluginError, public virtual BadStream
{
public:
virtual ~InvalidPluginConfigured() throw() {}
DEFINE_EXCEPTION_COPYTORS( InvalidPluginConfigured )
explicit InvalidPluginConfigured( const PluginsEnum_t& pid, const wxString& objname,
const char* eng );
explicit InvalidPluginConfigured( const PluginsEnum_t& pid, const wxString& objname,
InvalidPluginConfigured( PluginsEnum_t pid, const wxString& objname, const char* eng );
InvalidPluginConfigured( PluginsEnum_t pid, const wxString& objname,
const wxString& eng_msg, const wxString& xlt_msg );
};
};

View File

@ -33,74 +33,84 @@ namespace R5900Exception
class BaseExcept : public virtual Ps2Generic
{
public:
const cpuRegisters cpuState;
cpuRegisters cpuState;
public:
virtual ~BaseExcept() throw()=0;
explicit BaseExcept( const wxString& msg ) :
Ps2Generic( L"(EE) " + msg )
, cpuState( cpuRegs )
{
}
u32 GetPc() const { return cpuState.pc; }
bool IsDelaySlot() const { return !!cpuState.IsDelaySlot; }
protected:
void Init( const wxString& msg )
{
m_message = L"(EE) " + msg;
cpuState = cpuRegs;
}
void Init( const char*msg )
{
m_message = wxString::FromUTF8( msg );
cpuState = cpuRegs;
}
};
//////////////////////////////////////////////////////////////////////////////////
//
class AddressError : public BaseExcept
class BaseAddressError : public BaseExcept
{
public:
const bool OnWrite;
const u32 Address;
bool OnWrite;
u32 Address;
public:
virtual ~BaseAddressError() throw() {}
protected:
void Init( u32 ps2addr, bool onWrite, const wxString& msg )
{
BaseExcept::Init( wxsFormat( msg+L", addr=0x%x [%s]", ps2addr, onWrite ? L"store" : L"load" ) );
OnWrite = onWrite;
Address = ps2addr;
}
};
class AddressError : public BaseAddressError
{
public:
virtual ~AddressError() throw() {}
explicit AddressError( u32 ps2addr, bool onWrite ) :
BaseExcept( wxsFormat( L"Address error, addr=0x%x [%s]", ps2addr, onWrite ? L"store" : L"load" ) ),
OnWrite( onWrite ),
Address( ps2addr )
{}
AddressError( u32 ps2addr, bool onWrite )
{
BaseAddressError::Init( ps2addr, onWrite, L"Address error" );
}
};
//////////////////////////////////////////////////////////////////////////////////
//
class TLBMiss : public BaseExcept
class TLBMiss : public BaseAddressError
{
public:
const bool OnWrite;
const u32 Address;
public:
virtual ~TLBMiss() throw() {}
explicit TLBMiss( u32 ps2addr, bool onWrite ) :
BaseExcept( wxsFormat( L"Tlb Miss, addr=0x%x [%s]", ps2addr, onWrite ? L"store" : L"load" ) ),
OnWrite( onWrite ),
Address( ps2addr )
{}
TLBMiss( u32 ps2addr, bool onWrite )
{
BaseAddressError::Init( ps2addr, onWrite, L"TLB Miss" );
}
};
//////////////////////////////////////////////////////////////////////////////////
//
class BusError : public BaseExcept
class BusError : public BaseAddressError
{
public:
const bool OnWrite;
const u32 Address;
public:
virtual ~BusError() throw() {}
//
explicit BusError( u32 ps2addr, bool onWrite ) :
BaseExcept( wxsFormat( L"Bus Error, addr=0x%x [%s]", ps2addr, onWrite ? L"store" : L"load" ) ),
OnWrite( onWrite ),
Address( ps2addr )
{}
BusError( u32 ps2addr, bool onWrite )
{
BaseAddressError::Init( ps2addr, onWrite, L"Bus Error" );
}
};
//////////////////////////////////////////////////////////////////////////////////
@ -108,23 +118,25 @@ namespace R5900Exception
class Trap : public BaseExcept
{
public:
const u16 TrapCode;
u16 TrapCode;
public:
virtual ~Trap() throw() {}
// Generates a trap for immediate-style Trap opcodes
explicit Trap() :
BaseExcept( L"Trap" ),
TrapCode( 0 )
{}
Trap()
{
BaseExcept::Init( "Trap" );
TrapCode = 0;
}
// Generates a trap for register-style Trap instructions, which contain an
// error code in the opcode
explicit Trap( u16 trapcode ) :
BaseExcept( L"Trap" ),
TrapCode( trapcode )
{}
explicit Trap( u16 trapcode )
{
BaseExcept::Init( "Trap" ),
TrapCode = trapcode;
}
};
//////////////////////////////////////////////////////////////////////////////////
@ -134,9 +146,10 @@ namespace R5900Exception
public:
virtual ~DebugBreakpoint() throw() {}
explicit DebugBreakpoint() :
BaseExcept( L"Debug Breakpoint" )
{}
explicit DebugBreakpoint()
{
BaseExcept::Init( "Debug Breakpoint" );
}
};
}

View File

@ -189,7 +189,7 @@ namespace StateRecovery {
L"PCSX2 encountered an error while trying to backup/suspend the PS2 VirtualMachine state. "
L"You may resume emulation without losing any data, however the machine state will not be "
L"able to recover if you make changes to your PCSX2 configuration.\n\n"
L"Details: %s", ex.DisplayMessage().c_str() )
L"Details: %s", ex.FormatDisplayMessage().c_str() )
);
safe_delete( g_RecoveryState );
}

View File

@ -851,7 +851,7 @@ namespace Msgbox
void Except( const Exception::BaseException& src )
{
CallStack( src.DisplayMessage(), src.LogMessage(), wxEmptyString, L"PCSX2 Unhandled Exception", wxOK );
CallStack( src.FormatDisplayMessage(), src.FormatDiagnosticMessage(), wxEmptyString, L"PCSX2 Unhandled Exception", wxOK );
}
}

View File

@ -58,19 +58,18 @@ namespace Exception
public:
virtual ~CannotApplySettings() throw() {}
CannotApplySettings( const CannotApplySettings& src ) :
BaseException( src )
, m_Panel( src.m_Panel ) {}
explicit CannotApplySettings( Panels::BaseApplicableConfigPanel* thispanel, const char* msg=wxLt("Cannot apply new settings, one of the settings is invalid.") ) :
BaseException( msg )
, m_Panel( thispanel )
{}
explicit CannotApplySettings( Panels::BaseApplicableConfigPanel* thispanel, const char* msg=wxLt("Cannot apply new settings, one of the settings is invalid.") )
{
BaseException::InitBaseEx( msg );
m_Panel = thispanel;
}
explicit CannotApplySettings( Panels::BaseApplicableConfigPanel* thispanel, const wxString& msg_eng, const wxString& msg_xlt ) :
BaseException( msg_eng, msg_xlt )
, m_Panel( thispanel )
{}
explicit CannotApplySettings( Panels::BaseApplicableConfigPanel* thispanel, const wxString& msg_eng, const wxString& msg_xlt )
{
BaseException::InitBaseEx( msg_eng, msg_xlt );
m_Panel = thispanel;
}
Panels::BaseApplicableConfigPanel* GetPanel()
{

View File

@ -87,7 +87,7 @@ bool Panels::StaticApplyState::ApplyPage( int pageid, bool saveOnSuccess )
}
catch( Exception::CannotApplySettings& ex )
{
wxMessageBox( ex.DisplayMessage(), _("Cannot apply settings...") );
wxMessageBox( ex.FormatDisplayMessage(), _("Cannot apply settings...") );
if( ex.GetPanel() != NULL )
ex.GetPanel()->SetFocusToMe();

View File

@ -46,11 +46,7 @@ namespace Exception
class NotEnumerablePlugin : public BadStream
{
public:
virtual ~NotEnumerablePlugin() throw() {}
explicit NotEnumerablePlugin( const wxString& objname=wxEmptyString ) :
BadStream( objname, "" )
, BaseException( wxLt("File is not a PCSX2 plugin") )
{}
DEFINE_STREAM_EXCEPTION( NotEnumerablePlugin, wxLt("File is not a PCSX2 plugin") );
};
}
@ -460,7 +456,7 @@ sptr Panels::PluginSelectorPanel::EnumThread::ExecuteTask()
}
catch( Exception::BadStream& ex )
{
Console::Status( ex.LogMessage() );
Console::Status( ex.FormatDiagnosticMessage() );
}
pthread_testcancel();

View File

@ -57,7 +57,7 @@ void States_Load( const wxString& file )
// StateLoadErrors are only thorwn if the load failed prior to any virtual machine
// memory contents being changed. (usually missing file errors)
Console::Notice( ex.LogMessage() );
Console::Notice( ex.FormatDiagnosticMessage() );
}
catch( Exception::BaseException& ex )
{
@ -115,7 +115,7 @@ void States_Save( const wxString& file )
Console::Error( wxsFormat(
L"An error occurred while trying to save to file %s\n", file.c_str() ) +
L"Your emulation state has not been saved!\n"
L"\nError: " + ex.LogMessage()
L"\nError: " + ex.FormatDiagnosticMessage()
);
}
}

View File

@ -48,10 +48,12 @@ namespace Exception
{
public:
virtual ~StartupAborted() throw() {}
StartupAborted( const StartupAborted& src ) : BaseException( src ) {}
explicit StartupAborted( const wxString& msg_eng=L"Startup initialization was aborted by the user." ) :
BaseException( msg_eng, msg_eng ) { } // english messages only for this exception.
StartupAborted( const wxString& msg_eng=L"Startup initialization was aborted by the user." )
{
// english messages only for this exception.
BaseException::InitBaseEx( msg_eng, msg_eng );
}
};
}
@ -78,7 +80,7 @@ sptr AppEmuThread::ExecuteTask()
{
if( ex.StreamName == g_Conf->FullpathToBios() )
{
Msgbox::OkCancel( ex.DisplayMessage() +
Msgbox::OkCancel( ex.FormatDisplayMessage() +
_("\n\nPress Ok to go to the BIOS Configuration Panel.") );
}
else
@ -97,7 +99,7 @@ sptr AppEmuThread::ExecuteTask()
// Some other crap file failure >_<
}
int result = Msgbox::OkCancel( ex.DisplayMessage() +
int result = Msgbox::OkCancel( ex.FormatDisplayMessage() +
_("\n\nPress Ok to go to the Plugin Configuration Panel.") );
if( result == wxID_OK )
@ -112,7 +114,7 @@ sptr AppEmuThread::ExecuteTask()
{
// Sent the exception back to the main gui thread?
GetPluginManager().Close();
Msgbox::Alert( ex.DisplayMessage() );
Msgbox::Alert( ex.FormatDisplayMessage() );
}
return 0;

View File

@ -100,7 +100,7 @@ bool StreamException_LogFromErrno( const wxString& streamname, const wxChar* act
}
catch( Exception::Stream& ex )
{
Console::Notice( wxsFormat( L"%s: %s", action, ex.LogMessage().c_str() ) );
Console::Notice( wxsFormat( L"%s: %s", action, ex.FormatDiagnosticMessage().c_str() ) );
return true;
}
return false;
@ -115,7 +115,7 @@ bool StreamException_LogLastError( const wxString& streamname, const wxChar* act
}
catch( Exception::Stream& ex )
{
Console::Notice( wxsFormat( L"%s: %s", action, ex.LogMessage().c_str() ) );
Console::Notice( wxsFormat( L"%s: %s", action, ex.FormatDiagnosticMessage().c_str() ) );
return true;
}
return false;

View File

@ -54,7 +54,7 @@ microVUt(void) mVUinit(VURegs* vuRegsPtr, int vuIndex) {
mVUprint((vuIndex) ? "microVU1: init" : "microVU0: init");
mVU->cache = SysMmapEx((vuIndex ? 0x5f240000 : 0x5e240000), mVU->cacheSize + 0x1000, 0, (vuIndex ? "Micro VU1" : "Micro VU0"));
if (!mVU->cache) throw Exception::OutOfMemory(L"microVU Error: Failed to allocate recompiler memory!");
if (!mVU->cache) throw Exception::OutOfMemory( "microVU Error: Failed to allocate recompiler memory!" );
memset(mVU->cache, 0xcc, mVU->cacheSize + 0x1000);
memset(mVU->prog.prog, 0, sizeof(microProgram)*(mVU->prog.max+1));

View File

@ -351,7 +351,8 @@ void SuperVUAlloc(int vuindex)
{
throw Exception::OutOfMemory(
// untranslated diagnostic msg, use exception's default for translation
wxsFormat( L"Error > SuperVU failed to allocate recompiler memory (addr: 0x%x)", (u32)s_recVUMem )
wxsFormat( L"SuperVU failed to allocate recompiler memory (addr: 0x%x)", (u32)s_recVUMem ),
_("An out of memory error occured while attempting to reserve memory for the core recompilers.")
);
}