2009-09-08 12:08:10 +00:00
/* PCSX2 - PS2 Emulator for PCs
2010-05-03 14:08:02 +00:00
* Copyright ( C ) 2002 - 2010 PCSX2 Dev Team
2009-10-04 09:00:07 +00:00
*
2009-09-08 12:08:10 +00:00
* PCSX2 is free software : you can redistribute it and / or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found -
* ation , either version 3 of the License , or ( at your option ) any later version .
2009-04-27 02:04:31 +00:00
*
2009-09-08 12:08:10 +00:00
* PCSX2 is distributed in the hope that it will be useful , but WITHOUT ANY WARRANTY ;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE . See the GNU General Public License for more details .
2009-04-28 05:56:22 +00:00
*
2009-09-08 12:08:10 +00:00
* You should have received a copy of the GNU General Public License along with PCSX2 .
* If not , see < http : //www.gnu.org/licenses/>.
2009-04-27 02:04:31 +00:00
*/
2014-12-15 18:29:05 +00:00
// Avoid the following gcc error:
// Exceptions.cpp:133: error: inlining failed in call to always_inline ‘ void pxOnAssert(const DiagnosticOrigin&, const char*)’ : function not considered for inlining
// DEVASSERT_INLINE void pxOnAssert( const DiagnosticOrigin& origin, const char* msg)
// Exceptions.cpp:141: error: called from here
// pxOnAssert( origin, WX_STR(msg) ); // wc_str ???
//
// Feel free to provide a better fix
# if defined(__linux__) && defined(NDEBUG)
# undef NDEBUG
# endif
2009-04-27 02:04:31 +00:00
# include "PrecompiledHeader.h"
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
# include <wx/app.h>
2009-12-14 12:18:55 +00:00
# include "Threading.h"
2009-12-24 22:22:34 +00:00
# include "TlsVariable.inl"
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
2009-12-25 18:58:25 +00:00
# if defined(__UNIX__)
# include <signal.h>
# endif
2010-11-05 01:33:01 +00:00
// for lack of a better place...
Fnptr_OutOfMemory pxDoOutOfMemory = NULL ;
2009-09-12 02:58:22 +00:00
// ------------------------------------------------------------------------
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
// Force DevAssert to *not* inline for devel builds (allows using breakpoints to trap assertions,
// and force it to inline for release builds (optimizes it out completely since IsDevBuild is a
// const false).
2009-09-12 02:58:22 +00:00
//
# ifdef PCSX2_DEVBUILD
# define DEVASSERT_INLINE __noinline
# else
2010-08-09 04:10:38 +00:00
# define DEVASSERT_INLINE __fi
2009-09-12 02:58:22 +00:00
# endif
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
// Using a threadlocal assertion guard. Separate threads can assert at the same time.
// That's ok. What we don't want is the *same* thread recurse-asserting.
2009-12-24 22:22:34 +00:00
static DeclareTls ( int ) s_assert_guard ( 0 ) ;
2009-09-23 09:53:21 +00:00
2009-12-14 12:18:55 +00:00
pxDoAssertFnType * pxDoAssert = pxAssertImpl_LogIt ;
// make life easier for people using VC++ IDE by using this format, which allows double-click
// response times from the Output window...
wxString DiagnosticOrigin : : ToString ( const wxChar * msg ) const
{
2010-08-31 05:14:00 +00:00
FastFormatUnicode message ;
2009-12-14 12:18:55 +00:00
2014-06-29 10:42:58 +00:00
message . Write ( L " %ls(%d) : assertion failed: \n " , srcfile , line ) ;
2009-12-14 12:18:55 +00:00
if ( function ! = NULL )
2014-06-29 10:42:58 +00:00
message . Write ( " Function: %s \n " , function ) ;
2009-12-14 12:18:55 +00:00
2014-06-29 07:05:03 +00:00
message . Write ( L " Thread: %s \n " , WX_STR ( Threading : : pxGetCurrentThreadName ( ) ) ) ;
2009-12-14 12:18:55 +00:00
if ( condition ! = NULL )
2014-06-29 10:42:58 +00:00
message . Write ( L " Condition: %ls \n " , condition ) ;
2009-12-14 12:18:55 +00:00
if ( msg ! = NULL )
2014-06-29 10:42:58 +00:00
message . Write ( L " Message: %ls \n " , msg ) ;
2009-12-14 12:18:55 +00:00
return message ;
}
2009-12-25 18:00:51 +00:00
// Because wxTrap isn't available on Linux builds of wxWidgets (non-Debug, typically)
void pxTrap ( )
{
# if defined(__WXMSW__) && !defined(__WXMICROWIN__)
__debugbreak ( ) ;
# elif defined(__WXMAC__) && !defined(__DARWIN__)
# if __powerc
Debugger ( ) ;
# else
SysBreak ( ) ;
# endif
# elif defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS
Debugger ( ) ;
# elif defined(__UNIX__)
raise ( SIGTRAP ) ;
# else
// TODO
# endif // Win/Unix
}
2010-10-22 19:47:02 +00:00
bool pxAssertImpl_LogIt ( const DiagnosticOrigin & origin , const wxChar * msg )
{
//wxLogError( L"%s", origin.ToString( msg ).c_str() );
wxMessageOutputDebug ( ) . Printf ( L " %s " , origin . ToString ( msg ) . c_str ( ) ) ;
pxTrap ( ) ;
return false ;
}
2009-12-14 12:18:55 +00:00
DEVASSERT_INLINE void pxOnAssert ( const DiagnosticOrigin & origin , const wxChar * msg )
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
{
2010-08-06 05:46:09 +00:00
// Recursion guard: Allow at least one recursive call. This is useful because sometimes
// we get meaningless assertions while unwinding stack traces after exceptions have occurred.
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
RecursionGuard guard ( s_assert_guard ) ;
2014-12-12 20:46:52 +00:00
if ( guard . Counter > 2 ) { return pxTrap ( ) ; }
2009-10-04 09:00:07 +00:00
2009-12-14 12:18:55 +00:00
// wxWidgets doesn't come with debug builds on some Linux distros, and other distros make
// it difficult to use the debug build (compilation failures). To handle these I've had to
// bypass the internal wxWidgets assertion handler entirely, since it may not exist even if
// PCSX2 itself is compiled in debug mode (assertions enabled).
bool trapit ;
if ( pxDoAssert = = NULL )
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
{
// Note: Format uses MSVC's syntax for output window hotlinking.
2009-12-14 12:18:55 +00:00
trapit = pxAssertImpl_LogIt ( origin , msg ) ;
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
}
else
{
2009-12-14 12:18:55 +00:00
trapit = pxDoAssert ( origin , msg ) ;
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
}
2009-12-14 12:18:55 +00:00
2009-12-25 18:00:51 +00:00
if ( trapit ) { pxTrap ( ) ; }
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
}
2009-09-23 09:53:21 +00:00
2010-08-09 04:10:38 +00:00
__fi void pxOnAssert ( const DiagnosticOrigin & origin , const char * msg )
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
{
2009-12-14 12:18:55 +00:00
pxOnAssert ( origin , fromUTF8 ( msg ) ) ;
2009-09-12 02:58:22 +00:00
}
2014-06-29 06:57:33 +00:00
__fi void pxOnAssert ( const DiagnosticOrigin & origin , const wxString & msg )
{
2015-05-19 15:38:38 +00:00
pxOnAssert ( origin , msg . wc_str ( ) ) ;
2014-06-29 06:57:33 +00:00
}
__fi void pxOnAssert ( const DiagnosticOrigin & origin , const FastFormatUnicode & msg )
{
pxOnAssert ( origin , msg . c_str ( ) ) ;
}
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
2009-09-20 20:54:45 +00:00
// --------------------------------------------------------------------------------------
2010-06-28 18:03:54 +00:00
// BaseException (implementations)
2009-09-20 20:54:45 +00:00
// --------------------------------------------------------------------------------------
2010-04-27 13:12:03 +00:00
BaseException : : ~ BaseException ( ) throw ( ) { }
2009-04-27 02:04:31 +00:00
2010-08-06 05:46:09 +00:00
BaseException & BaseException : : SetBothMsgs ( const wxChar * msg_diag )
2009-09-20 20:54:45 +00:00
{
2014-06-29 07:05:03 +00:00
m_message_user = msg_diag ? wxString ( wxGetTranslation ( msg_diag ) ) : wxString ( " " ) ;
2010-08-06 05:46:09 +00:00
return SetDiagMsg ( msg_diag ) ;
2009-09-20 20:54:45 +00:00
}
2009-04-28 05:56:22 +00:00
2010-06-28 18:03:54 +00:00
BaseException & BaseException : : SetDiagMsg ( const wxString & msg_diag )
2009-09-20 20:54:45 +00:00
{
2010-06-28 18:03:54 +00:00
m_message_diag = msg_diag ;
return * this ;
}
2009-09-01 00:43:28 +00:00
2010-06-28 18:03:54 +00:00
BaseException & BaseException : : SetUserMsg ( const wxString & msg_user )
{
m_message_user = msg_user ;
return * this ;
2009-09-20 20:54:45 +00:00
}
2010-04-27 13:12:03 +00:00
wxString BaseException : : FormatDiagnosticMessage ( ) const
2009-09-20 20:54:45 +00:00
{
2010-06-28 18:03:54 +00:00
return m_message_diag ;
2009-09-20 20:54:45 +00:00
}
2010-06-28 18:03:54 +00:00
wxString BaseException : : FormatDisplayMessage ( ) const
{
return m_message_user . IsEmpty ( ) ? m_message_diag : m_message_user ;
}
// --------------------------------------------------------------------------------------
// Exception::RuntimeError (implementations)
// --------------------------------------------------------------------------------------
2010-04-27 13:12:03 +00:00
Exception : : RuntimeError : : RuntimeError ( const std : : runtime_error & ex , const wxString & prefix )
{
2010-06-28 18:03:54 +00:00
IsSilent = false ;
2010-10-19 09:51:57 +00:00
SetDiagMsg ( pxsFmt ( L " STL Runtime Error%s: %s " ,
2014-06-29 07:05:03 +00:00
( prefix . IsEmpty ( ) ? L " " : pxsFmt ( L " (%s) " , WX_STR ( prefix ) ) . c_str ( ) ) ,
WX_STR ( fromUTF8 ( ex . what ( ) ) )
2010-05-07 03:20:58 +00:00
) ) ;
}
Exception : : RuntimeError : : RuntimeError ( const std : : exception & ex , const wxString & prefix )
{
2010-06-28 18:03:54 +00:00
IsSilent = false ;
2010-10-19 09:51:57 +00:00
SetDiagMsg ( pxsFmt ( L " STL Exception%s: %s " ,
2014-06-29 07:05:03 +00:00
( prefix . IsEmpty ( ) ? L " " : pxsFmt ( L " (%s) " , WX_STR ( prefix ) ) . c_str ( ) ) ,
WX_STR ( fromUTF8 ( ex . what ( ) ) )
2010-04-27 13:12:03 +00:00
) ) ;
}
2010-06-28 18:03:54 +00:00
// --------------------------------------------------------------------------------------
// Exception::OutOfMemory (implementations)
// --------------------------------------------------------------------------------------
Exception : : OutOfMemory : : OutOfMemory ( const wxString & allocdesc )
2009-10-07 19:20:11 +00:00
{
2010-06-28 18:03:54 +00:00
AllocDescription = allocdesc ;
2009-10-07 19:20:11 +00:00
}
2010-06-28 18:03:54 +00:00
wxString Exception : : OutOfMemory : : FormatDiagnosticMessage ( ) const
2009-10-07 19:20:11 +00:00
{
2010-11-05 01:33:01 +00:00
FastFormatUnicode retmsg ;
retmsg . Write ( L " Out of memory " ) ;
if ( ! AllocDescription . IsEmpty ( ) )
2014-06-29 07:05:03 +00:00
retmsg . Write ( L " while allocating '%s' " , WX_STR ( AllocDescription ) ) ;
2010-10-29 02:49:01 +00:00
2010-11-05 01:33:01 +00:00
if ( ! m_message_diag . IsEmpty ( ) )
2014-06-29 07:05:03 +00:00
retmsg . Write ( L " : \n %s " , WX_STR ( m_message_diag ) ) ;
2010-11-05 01:33:01 +00:00
return retmsg ;
2009-10-07 19:20:11 +00:00
}
2010-06-28 18:03:54 +00:00
wxString Exception : : OutOfMemory : : FormatDisplayMessage ( ) const
{
2010-11-05 01:33:01 +00:00
FastFormatUnicode retmsg ;
retmsg . Write ( L " %s " , _ ( " Oh noes! Out of memory! " ) ) ;
2010-12-30 06:21:07 +00:00
if ( ! m_message_user . IsEmpty ( ) )
2014-06-29 07:05:03 +00:00
retmsg . Write ( L " \n \n %s " , WX_STR ( m_message_user ) ) ;
2010-11-05 01:33:01 +00:00
return retmsg ;
2010-10-29 02:49:01 +00:00
}
// --------------------------------------------------------------------------------------
// Exception::VirtualMemoryMapConflict (implementations)
// --------------------------------------------------------------------------------------
Exception : : VirtualMemoryMapConflict : : VirtualMemoryMapConflict ( const wxString & allocdesc )
{
AllocDescription = allocdesc ;
m_message_user = _ ( " Virtual memory mapping failure! Your system may have conflicting device drivers, services, or may simply have insufficient memory or resources to meet PCSX2's lofty needs. " ) ;
}
wxString Exception : : VirtualMemoryMapConflict : : FormatDiagnosticMessage ( ) const
{
2010-11-05 01:33:01 +00:00
FastFormatUnicode retmsg ;
retmsg . Write ( L " Virtual memory map failed " ) ;
if ( ! AllocDescription . IsEmpty ( ) )
2014-06-29 07:05:03 +00:00
retmsg . Write ( L " while reserving '%s' " , WX_STR ( AllocDescription ) ) ;
2010-10-29 02:49:01 +00:00
2010-11-05 01:33:01 +00:00
if ( ! m_message_diag . IsEmpty ( ) )
2014-06-29 07:05:03 +00:00
retmsg . Write ( L " : \n %s " , WX_STR ( m_message_diag ) ) ;
2010-11-05 01:33:01 +00:00
return retmsg ;
2010-10-29 02:49:01 +00:00
}
wxString Exception : : VirtualMemoryMapConflict : : FormatDisplayMessage ( ) const
{
2010-11-05 01:33:01 +00:00
FastFormatUnicode retmsg ;
retmsg . Write ( L " %s " ,
2012-08-10 10:10:55 +00:00
pxE ( L " There is not enough virtual memory available, or necessary virtual memory mappings have already been reserved by other processes, services, or DLLs. "
2010-11-05 01:33:01 +00:00
)
) ;
if ( ! m_message_diag . IsEmpty ( ) )
2014-06-29 07:05:03 +00:00
retmsg . Write ( L " \n \n %s " , WX_STR ( m_message_diag ) ) ;
2010-11-05 01:33:01 +00:00
return retmsg ;
2010-06-28 18:03:54 +00:00
}
2009-09-20 20:54:45 +00:00
// ------------------------------------------------------------------------
2010-06-28 18:03:54 +00:00
wxString Exception : : CancelEvent : : FormatDiagnosticMessage ( ) const
2009-09-20 20:54:45 +00:00
{
2010-06-28 18:03:54 +00:00
return L " Action canceled: " + m_message_diag ;
2009-09-20 20:54:45 +00:00
}
2010-06-28 18:03:54 +00:00
wxString Exception : : CancelEvent : : FormatDisplayMessage ( ) const
2009-09-20 20:54:45 +00:00
{
2010-06-28 18:03:54 +00:00
return L " Action canceled: " + m_message_diag ;
2009-09-20 20:54:45 +00:00
}
2010-11-05 01:33:01 +00:00
// --------------------------------------------------------------------------------------
// Exception::BadStream (implementations)
// --------------------------------------------------------------------------------------
wxString Exception : : BadStream : : FormatDiagnosticMessage ( ) const
2009-09-20 20:54:45 +00:00
{
2010-11-05 01:33:01 +00:00
FastFormatUnicode retval ;
_formatDiagMsg ( retval ) ;
return retval ;
}
wxString Exception : : BadStream : : FormatDisplayMessage ( ) const
{
FastFormatUnicode retval ;
_formatUserMsg ( retval ) ;
return retval ;
2009-09-20 20:54:45 +00:00
}
2010-11-22 16:24:54 +00:00
void Exception : : BadStream : : _formatDiagMsg ( FastFormatUnicode & dest ) const
2009-09-20 20:54:45 +00:00
{
2010-11-05 01:33:01 +00:00
dest . Write ( L " Path: " ) ;
2010-06-28 18:03:54 +00:00
if ( ! StreamName . IsEmpty ( ) )
2014-06-29 07:05:03 +00:00
dest . Write ( L " %s " , WX_STR ( StreamName ) ) ;
2010-11-05 01:33:01 +00:00
else
dest . Write ( L " [Unnamed or unknown] " ) ;
2010-06-28 18:03:54 +00:00
2010-11-05 01:33:01 +00:00
if ( ! m_message_diag . IsEmpty ( ) )
2014-06-29 07:05:03 +00:00
dest . Write ( L " \n %s " , WX_STR ( m_message_diag ) ) ;
2010-11-05 01:33:01 +00:00
}
void Exception : : BadStream : : _formatUserMsg ( FastFormatUnicode & dest ) const
{
dest . Write ( _ ( " Path: " ) ) ;
if ( ! StreamName . IsEmpty ( ) )
2014-06-29 07:05:03 +00:00
dest . Write ( L " %s " , WX_STR ( StreamName ) ) ;
2010-11-05 01:33:01 +00:00
else
dest . Write ( _ ( " [Unnamed or unknown] " ) ) ;
if ( ! m_message_user . IsEmpty ( ) )
2014-06-29 07:05:03 +00:00
dest . Write ( L " \n %s " , WX_STR ( m_message_user ) ) ;
2010-11-05 01:33:01 +00:00
}
// --------------------------------------------------------------------------------------
// Exception::CannotCreateStream (implementations)
// --------------------------------------------------------------------------------------
wxString Exception : : CannotCreateStream : : FormatDiagnosticMessage ( ) const
{
FastFormatUnicode retval ;
retval . Write ( " File could not be created. " ) ;
_formatDiagMsg ( retval ) ;
return retval ;
}
wxString Exception : : CannotCreateStream : : FormatDisplayMessage ( ) const
{
FastFormatUnicode retval ;
retval . Write ( _ ( " A file could not be created. " ) ) ;
2010-12-14 22:41:02 +00:00
retval . Write ( " \n " ) ;
2010-11-05 01:33:01 +00:00
_formatUserMsg ( retval ) ;
return retval ;
}
// --------------------------------------------------------------------------------------
// Exception::FileNotFound (implementations)
// --------------------------------------------------------------------------------------
wxString Exception : : FileNotFound : : FormatDiagnosticMessage ( ) const
{
FastFormatUnicode retval ;
2010-12-14 22:41:02 +00:00
retval . Write ( " File not found. \n " ) ;
2010-11-05 01:33:01 +00:00
_formatDiagMsg ( retval ) ;
return retval ;
}
wxString Exception : : FileNotFound : : FormatDisplayMessage ( ) const
{
FastFormatUnicode retval ;
retval . Write ( _ ( " File not found. " ) ) ;
2010-12-14 22:41:02 +00:00
retval . Write ( " \n " ) ;
2010-11-05 01:33:01 +00:00
_formatUserMsg ( retval ) ;
return retval ;
}
// --------------------------------------------------------------------------------------
// Exception::AccessDenied (implementations)
// --------------------------------------------------------------------------------------
wxString Exception : : AccessDenied : : FormatDiagnosticMessage ( ) const
{
FastFormatUnicode retval ;
2010-12-14 22:41:02 +00:00
retval . Write ( " Permission denied to file. \n " ) ;
2010-11-05 01:33:01 +00:00
_formatDiagMsg ( retval ) ;
return retval ;
}
wxString Exception : : AccessDenied : : FormatDisplayMessage ( ) const
{
FastFormatUnicode retval ;
retval . Write ( _ ( " Permission denied while trying to open file, likely due to insufficient user account rights. " ) ) ;
2010-12-14 22:41:02 +00:00
retval . Write ( " \n " ) ;
2010-11-05 01:33:01 +00:00
_formatUserMsg ( retval ) ;
return retval ;
}
// --------------------------------------------------------------------------------------
// Exception::EndOfStream (implementations)
// --------------------------------------------------------------------------------------
wxString Exception : : EndOfStream : : FormatDiagnosticMessage ( ) const
{
FastFormatUnicode retval ;
2010-12-14 22:41:02 +00:00
retval . Write ( " Unexpected end of file or stream. \n " ) ;
2010-11-05 01:33:01 +00:00
_formatDiagMsg ( retval ) ;
return retval ;
}
wxString Exception : : EndOfStream : : FormatDisplayMessage ( ) const
{
FastFormatUnicode retval ;
retval . Write ( _ ( " Unexpected end of file or stream encountered. File is probably truncated or corrupted. " ) ) ;
2010-12-14 22:41:02 +00:00
retval . Write ( " \n " ) ;
2010-11-05 01:33:01 +00:00
_formatUserMsg ( retval ) ;
2010-06-28 18:03:54 +00:00
return retval ;
2009-09-20 20:54:45 +00:00
}
2010-10-18 01:40:49 +00:00
// --------------------------------------------------------------------------------------
// Exceptions from Errno (POSIX)
// --------------------------------------------------------------------------------------
// Translates an Errno code into an exception.
// Throws an exception based on the given error code (usually taken from ANSI C's errno)
2010-10-18 15:46:05 +00:00
BaseException * Exception : : FromErrno ( const wxString & streamname , int errcode )
2010-10-18 01:40:49 +00:00
{
pxAssumeDev ( errcode ! = 0 , " Invalid NULL error code? (errno) " ) ;
switch ( errcode )
{
case EINVAL :
pxFailDev ( L " Invalid argument " ) ;
2010-11-05 01:33:01 +00:00
return & ( new Exception : : BadStream ( streamname ) ) - > SetDiagMsg ( L " Invalid argument? (likely caused by an unforgivable programmer error!) " ) ;
2010-10-18 01:40:49 +00:00
case EACCES : // Access denied!
return new Exception : : AccessDenied ( streamname ) ;
case EMFILE : // Too many open files!
return & ( new Exception : : CannotCreateStream ( streamname ) ) - > SetDiagMsg ( L " Too many open files " ) ; // File handle allocation failure
case EEXIST :
return & ( new Exception : : CannotCreateStream ( streamname ) ) - > SetDiagMsg ( L " File already exists " ) ;
case ENOENT : // File not found!
return new Exception : : FileNotFound ( streamname ) ;
case EPIPE :
return & ( new Exception : : BadStream ( streamname ) ) - > SetDiagMsg ( L " Broken pipe " ) ;
case EBADF :
return & ( new Exception : : BadStream ( streamname ) ) - > SetDiagMsg ( L " Bad file number " ) ;
default :
2010-11-05 01:33:01 +00:00
return & ( new Exception : : BadStream ( streamname ) ) - > SetDiagMsg ( pxsFmt ( L " General file/stream error [errno: %d] " , errcode ) ) ;
2010-10-18 01:40:49 +00:00
}
}