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
*/
2021-09-03 10:43:33 +00:00
# define WXINTL_NO_GETTEXT_MACRO
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-25 18:58:25 +00:00
# if defined(__UNIX__)
# include <signal.h>
# endif
2021-09-03 10:43:33 +00:00
# include "common/Dependencies.h" // _ macro
2021-09-01 20:31:46 +00:00
# include "common/Threading.h"
# include "common/General.h"
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
2016-11-12 15:28:37 +00:00
# define DEVASSERT_INLINE __noinline
2009-09-12 02:58:22 +00:00
# else
2016-11-12 15:28:37 +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.
2016-11-12 15:28:37 +00:00
static DeclareTls ( int ) s_assert_guard ( 0 ) ;
2009-09-23 09:53:21 +00:00
2021-09-06 18:28:26 +00:00
pxDoAssertFnType * pxDoAssert = pxAssertImpl_LogIt ;
2009-12-14 12:18:55 +00:00
// make life easier for people using VC++ IDE by using this format, which allows double-click
// response times from the Output window...
2021-09-06 18:28:26 +00:00
wxString DiagnosticOrigin : : ToString ( const wxChar * msg ) const
2009-12-14 12:18:55 +00:00
{
2021-09-06 18:28:26 +00:00
FastFormatUnicode message ;
2009-12-14 12:18:55 +00:00
2021-09-06 18:28:26 +00:00
message . Write ( L " %ls(%d) : assertion failed: \n " , srcfile , line ) ;
2009-12-14 12:18:55 +00:00
2021-09-06 18:28:26 +00:00
if ( function ! = NULL )
message . Write ( " Function: %s \n " , function ) ;
2009-12-14 12:18:55 +00:00
2021-09-06 18:28:26 +00:00
message . Write ( L " Thread: %s \n " , WX_STR ( Threading : : pxGetCurrentThreadName ( ) ) ) ;
2009-12-14 12:18:55 +00:00
2021-09-06 18:28:26 +00:00
if ( condition ! = NULL )
message . Write ( L " Condition: %ls \n " , condition ) ;
2009-12-14 12:18:55 +00:00
2021-09-06 18:28:26 +00:00
if ( msg ! = NULL )
message . Write ( L " Message: %ls \n " , msg ) ;
2009-12-14 12:18:55 +00:00
2021-09-06 18:28:26 +00:00
return message ;
2009-12-14 12:18:55 +00:00
}
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__)
2021-09-06 18:28:26 +00:00
__debugbreak ( ) ;
2009-12-25 18:00:51 +00:00
# elif defined(__WXMAC__) && !defined(__DARWIN__)
2016-11-12 15:28:37 +00:00
# if __powerc
2021-09-06 18:28:26 +00:00
Debugger ( ) ;
2016-11-12 15:28:37 +00:00
# else
2021-09-06 18:28:26 +00:00
SysBreak ( ) ;
2016-11-12 15:28:37 +00:00
# endif
2009-12-25 18:00:51 +00:00
# elif defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS
2021-09-06 18:28:26 +00:00
Debugger ( ) ;
2009-12-25 18:00:51 +00:00
# elif defined(__UNIX__)
2021-09-06 18:28:26 +00:00
raise ( SIGTRAP ) ;
2009-12-25 18:00:51 +00:00
# else
2016-11-12 15:28:37 +00:00
// TODO
2009-12-25 18:00:51 +00:00
# endif // Win/Unix
}
2010-10-22 19:47:02 +00:00
2021-09-06 18:28:26 +00:00
bool pxAssertImpl_LogIt ( const DiagnosticOrigin & origin , const wxChar * msg )
2010-10-22 19:47:02 +00:00
{
2021-09-06 18:28:26 +00:00
//wxLogError( L"%s", origin.ToString( msg ).c_str() );
wxMessageOutputDebug ( ) . Printf ( L " %s " , origin . ToString ( msg ) . c_str ( ) ) ;
pxTrap ( ) ;
return false ;
2010-10-22 19:47:02 +00:00
}
2021-09-06 18:28:26 +00:00
DEVASSERT_INLINE void pxOnAssert ( const DiagnosticOrigin & origin , const wxString & 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
{
2021-09-06 18:28:26 +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.
2010-08-06 05:46:09 +00:00
2021-09-06 18:28:26 +00:00
RecursionGuard guard ( s_assert_guard ) ;
if ( guard . Counter > 2 )
{
return pxTrap ( ) ;
}
2009-10-04 09:00:07 +00:00
2021-09-06 18:28:26 +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).
2009-12-14 12:18:55 +00:00
2021-09-06 18:28:26 +00:00
bool trapit ;
2009-12-14 12:18:55 +00:00
2021-09-06 18:28:26 +00:00
if ( pxDoAssert = = NULL )
{
// Note: Format uses MSVC's syntax for output window hotlinking.
trapit = pxAssertImpl_LogIt ( origin , msg . wc_str ( ) ) ;
}
else
{
trapit = pxDoAssert ( origin , msg . wc_str ( ) ) ;
}
2009-12-14 12:18:55 +00:00
2021-09-06 18:28:26 +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
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
// --------------------------------------------------------------------------------------
2021-09-06 18:28:26 +00:00
BaseException & BaseException : : SetBothMsgs ( const wxChar * msg_diag )
2009-09-20 20:54:45 +00:00
{
2021-09-06 18:28:26 +00:00
m_message_user = msg_diag ? wxString ( wxGetTranslation ( msg_diag ) ) : wxString ( " " ) ;
return SetDiagMsg ( msg_diag ) ;
2009-09-20 20:54:45 +00:00
}
2009-04-28 05:56:22 +00:00
2021-09-06 18:28:26 +00:00
BaseException & BaseException : : SetDiagMsg ( const wxString & msg_diag )
2009-09-20 20:54:45 +00:00
{
2021-09-06 18:28:26 +00:00
m_message_diag = msg_diag ;
return * this ;
2010-06-28 18:03:54 +00:00
}
2009-09-01 00:43:28 +00:00
2021-09-06 18:28:26 +00:00
BaseException & BaseException : : SetUserMsg ( const wxString & msg_user )
2010-06-28 18:03:54 +00:00
{
2021-09-06 18:28:26 +00:00
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
{
2021-09-06 18:28:26 +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
{
2021-09-06 18:28:26 +00:00
return m_message_user . IsEmpty ( ) ? m_message_diag : m_message_user ;
2010-06-28 18:03:54 +00:00
}
// --------------------------------------------------------------------------------------
// Exception::RuntimeError (implementations)
// --------------------------------------------------------------------------------------
2021-09-06 18:28:26 +00:00
Exception : : RuntimeError : : RuntimeError ( const std : : runtime_error & ex , const wxString & prefix )
2010-04-27 13:12:03 +00:00
{
2021-09-06 18:28:26 +00:00
IsSilent = false ;
2010-06-28 18:03:54 +00:00
2021-09-06 18:28:26 +00:00
SetDiagMsg ( pxsFmt ( L " STL Runtime Error%s: %s " ,
( prefix . IsEmpty ( ) ? L " " : pxsFmt ( L " (%s) " , WX_STR ( prefix ) ) . c_str ( ) ) ,
WX_STR ( fromUTF8 ( ex . what ( ) ) ) ) ) ;
2010-05-07 03:20:58 +00:00
}
2021-09-06 18:28:26 +00:00
Exception : : RuntimeError : : RuntimeError ( const std : : exception & ex , const wxString & prefix )
2010-05-07 03:20:58 +00:00
{
2021-09-06 18:28:26 +00:00
IsSilent = false ;
2010-06-28 18:03:54 +00:00
2021-09-06 18:28:26 +00:00
SetDiagMsg ( pxsFmt ( L " STL Exception%s: %s " ,
( 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)
// --------------------------------------------------------------------------------------
2021-09-06 18:28:26 +00:00
Exception : : OutOfMemory : : OutOfMemory ( const wxString & allocdesc )
2009-10-07 19:20:11 +00:00
{
2021-09-06 18:28:26 +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
{
2021-09-06 18:28:26 +00:00
FastFormatUnicode retmsg ;
retmsg . Write ( L " Out of memory " ) ;
if ( ! AllocDescription . IsEmpty ( ) )
retmsg . Write ( L " while allocating '%s' " , WX_STR ( AllocDescription ) ) ;
2010-10-29 02:49:01 +00:00
2021-09-06 18:28:26 +00:00
if ( ! m_message_diag . IsEmpty ( ) )
retmsg . Write ( L " : \n %s " , WX_STR ( m_message_diag ) ) ;
2016-11-12 15:28:37 +00:00
2021-09-06 18:28:26 +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
{
2021-09-06 18:28:26 +00:00
FastFormatUnicode retmsg ;
retmsg . Write ( L " %s " , _ ( " Oh noes! Out of memory! " ) ) ;
2010-11-05 01:33:01 +00:00
2021-09-06 18:28:26 +00:00
if ( ! m_message_user . IsEmpty ( ) )
retmsg . Write ( L " \n \n %s " , WX_STR ( m_message_user ) ) ;
2010-11-05 01:33:01 +00:00
2021-09-06 18:28:26 +00:00
return retmsg ;
2010-10-29 02:49:01 +00:00
}
// --------------------------------------------------------------------------------------
// Exception::VirtualMemoryMapConflict (implementations)
// --------------------------------------------------------------------------------------
2021-09-06 18:28:26 +00:00
Exception : : VirtualMemoryMapConflict : : VirtualMemoryMapConflict ( const wxString & allocdesc )
2010-10-29 02:49:01 +00:00
{
2021-09-06 18:28:26 +00:00
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. " ) ;
2010-10-29 02:49:01 +00:00
}
wxString Exception : : VirtualMemoryMapConflict : : FormatDiagnosticMessage ( ) const
{
2021-09-06 18:28:26 +00:00
FastFormatUnicode retmsg ;
retmsg . Write ( L " Virtual memory map failed " ) ;
if ( ! AllocDescription . IsEmpty ( ) )
retmsg . Write ( L " while reserving '%s' " , WX_STR ( AllocDescription ) ) ;
2016-11-12 15:28:37 +00:00
2021-09-06 18:28:26 +00:00
if ( ! m_message_diag . IsEmpty ( ) )
retmsg . Write ( L " : \n %s " , WX_STR ( m_message_diag ) ) ;
2010-10-29 02:49:01 +00:00
2021-09-06 18:28:26 +00:00
return retmsg ;
2010-10-29 02:49:01 +00:00
}
wxString Exception : : VirtualMemoryMapConflict : : FormatDisplayMessage ( ) const
{
2021-09-06 18:28:26 +00:00
FastFormatUnicode retmsg ;
retmsg . Write ( L " %s " ,
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
2021-09-06 18:28:26 +00:00
if ( ! m_message_diag . IsEmpty ( ) )
retmsg . Write ( L " \n \n %s " , WX_STR ( m_message_diag ) ) ;
2010-11-05 01:33:01 +00:00
2021-09-06 18:28:26 +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
{
2021-09-06 18:28:26 +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
{
2021-09-06 18:28:26 +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
{
2021-09-06 18:28:26 +00:00
FastFormatUnicode retval ;
_formatDiagMsg ( retval ) ;
return retval ;
2010-11-05 01:33:01 +00:00
}
wxString Exception : : BadStream : : FormatDisplayMessage ( ) const
{
2021-09-06 18:28:26 +00:00
FastFormatUnicode retval ;
_formatUserMsg ( retval ) ;
return retval ;
2009-09-20 20:54:45 +00:00
}
2021-09-06 18:28:26 +00:00
void Exception : : BadStream : : _formatDiagMsg ( FastFormatUnicode & dest ) const
2009-09-20 20:54:45 +00:00
{
2021-09-06 18:28:26 +00:00
dest . Write ( L " Path: " ) ;
if ( ! StreamName . IsEmpty ( ) )
dest . Write ( L " %s " , WX_STR ( StreamName ) ) ;
else
dest . Write ( L " [Unnamed or unknown] " ) ;
2010-06-28 18:03:54 +00:00
2021-09-06 18:28:26 +00:00
if ( ! m_message_diag . IsEmpty ( ) )
dest . Write ( L " \n %s " , WX_STR ( m_message_diag ) ) ;
2010-11-05 01:33:01 +00:00
}
2021-09-06 18:28:26 +00:00
void Exception : : BadStream : : _formatUserMsg ( FastFormatUnicode & dest ) const
2010-11-05 01:33:01 +00:00
{
2021-09-06 18:28:26 +00:00
dest . Write ( _ ( " Path: " ) ) ;
if ( ! StreamName . IsEmpty ( ) )
dest . Write ( L " %s " , WX_STR ( StreamName ) ) ;
else
dest . Write ( _ ( " [Unnamed or unknown] " ) ) ;
2010-11-05 01:33:01 +00:00
2021-09-06 18:28:26 +00:00
if ( ! m_message_user . IsEmpty ( ) )
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
{
2021-09-06 18:28:26 +00:00
FastFormatUnicode retval ;
retval . Write ( " File could not be created. " ) ;
_formatDiagMsg ( retval ) ;
return retval ;
2010-11-05 01:33:01 +00:00
}
wxString Exception : : CannotCreateStream : : FormatDisplayMessage ( ) const
{
2021-09-06 18:28:26 +00:00
FastFormatUnicode retval ;
retval . Write ( _ ( " A file could not be created. " ) ) ;
retval . Write ( " \n " ) ;
_formatUserMsg ( retval ) ;
return retval ;
2010-11-05 01:33:01 +00:00
}
// --------------------------------------------------------------------------------------
// Exception::FileNotFound (implementations)
// --------------------------------------------------------------------------------------
wxString Exception : : FileNotFound : : FormatDiagnosticMessage ( ) const
{
2021-09-06 18:28:26 +00:00
FastFormatUnicode retval ;
retval . Write ( " File not found. \n " ) ;
_formatDiagMsg ( retval ) ;
return retval ;
2010-11-05 01:33:01 +00:00
}
wxString Exception : : FileNotFound : : FormatDisplayMessage ( ) const
{
2021-09-06 18:28:26 +00:00
FastFormatUnicode retval ;
retval . Write ( _ ( " File not found. " ) ) ;
retval . Write ( " \n " ) ;
_formatUserMsg ( retval ) ;
return retval ;
2010-11-05 01:33:01 +00:00
}
// --------------------------------------------------------------------------------------
// Exception::AccessDenied (implementations)
// --------------------------------------------------------------------------------------
wxString Exception : : AccessDenied : : FormatDiagnosticMessage ( ) const
{
2021-09-06 18:28:26 +00:00
FastFormatUnicode retval ;
retval . Write ( " Permission denied to file. \n " ) ;
_formatDiagMsg ( retval ) ;
return retval ;
2010-11-05 01:33:01 +00:00
}
wxString Exception : : AccessDenied : : FormatDisplayMessage ( ) const
{
2021-09-06 18:28:26 +00:00
FastFormatUnicode retval ;
retval . Write ( _ ( " Permission denied while trying to open file, likely due to insufficient user account rights. " ) ) ;
retval . Write ( " \n " ) ;
_formatUserMsg ( retval ) ;
return retval ;
2010-11-05 01:33:01 +00:00
}
// --------------------------------------------------------------------------------------
// Exception::EndOfStream (implementations)
// --------------------------------------------------------------------------------------
wxString Exception : : EndOfStream : : FormatDiagnosticMessage ( ) const
{
2021-09-06 18:28:26 +00:00
FastFormatUnicode retval ;
retval . Write ( " Unexpected end of file or stream. \n " ) ;
_formatDiagMsg ( retval ) ;
return retval ;
2010-11-05 01:33:01 +00:00
}
wxString Exception : : EndOfStream : : FormatDisplayMessage ( ) const
{
2021-09-06 18:28:26 +00:00
FastFormatUnicode retval ;
retval . Write ( _ ( " Unexpected end of file or stream encountered. File is probably truncated or corrupted. " ) ) ;
retval . Write ( " \n " ) ;
_formatUserMsg ( retval ) ;
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)
2021-09-06 18:28:26 +00:00
BaseException * Exception : : FromErrno ( const wxString & streamname , int errcode )
2010-10-18 01:40:49 +00:00
{
2021-09-06 18:28:26 +00:00
pxAssumeDev ( errcode ! = 0 , " Invalid NULL error code? (errno) " ) ;
2010-10-18 01:40:49 +00:00
2021-09-06 18:28:26 +00:00
switch ( errcode )
{
case EINVAL :
pxFailDev ( L " Invalid argument " ) ;
return & ( new Exception : : BadStream ( streamname ) ) - > SetDiagMsg ( L " Invalid argument? (likely caused by an unforgivable programmer error!) " ) ;
2010-10-18 01:40:49 +00:00
2021-09-06 18:28:26 +00:00
case EACCES : // Access denied!
return new Exception : : AccessDenied ( streamname ) ;
2010-10-18 01:40:49 +00:00
2021-09-06 18:28:26 +00:00
case EMFILE : // Too many open files!
return & ( new Exception : : CannotCreateStream ( streamname ) ) - > SetDiagMsg ( L " Too many open files " ) ; // File handle allocation failure
2010-10-18 01:40:49 +00:00
2021-09-06 18:28:26 +00:00
case EEXIST :
return & ( new Exception : : CannotCreateStream ( streamname ) ) - > SetDiagMsg ( L " File already exists " ) ;
2010-10-18 01:40:49 +00:00
2021-09-06 18:28:26 +00:00
case ENOENT : // File not found!
return new Exception : : FileNotFound ( streamname ) ;
2010-10-18 01:40:49 +00:00
2021-09-06 18:28:26 +00:00
case EPIPE :
return & ( new Exception : : BadStream ( streamname ) ) - > SetDiagMsg ( L " Broken pipe " ) ;
2010-10-18 01:40:49 +00:00
2021-09-06 18:28:26 +00:00
case EBADF :
return & ( new Exception : : BadStream ( streamname ) ) - > SetDiagMsg ( L " Bad file number " ) ;
2010-10-18 01:40:49 +00:00
2021-09-06 18:28:26 +00:00
default :
return & ( new Exception : : BadStream ( streamname ) ) - > SetDiagMsg ( pxsFmt ( L " General file/stream error [errno: %d] " , errcode ) ) ;
}
2010-10-18 01:40:49 +00:00
}