Files
itgmania212121/stepmania/src/RageException.cpp
T

90 lines
2.7 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2002-06-14 22:25:22 +00:00
#include "RageException.h"
#include "RageUtil.h"
2002-12-21 18:12:03 +00:00
#include "RageLog.h"
2004-12-01 01:11:14 +00:00
#include <cstdarg>
2004-01-31 01:23:20 +00:00
#if defined(_WINDOWS) && defined(DEBUG)
#include <windows.h>
2006-09-15 19:40:32 +00:00
#elif defined(MACOSX)
#include "archutils/Darwin/Crash.h"
using CrashHandler::IsDebuggerPresent;
using CrashHandler::DebugBreak;
#endif
2002-06-14 22:25:22 +00:00
static void (*g_CleanupHandler)( const RString &sError ) = NULL;
void RageException::SetCleanupHandler( void (*pHandler)(const RString &sError) )
{
g_CleanupHandler = pHandler;
}
2006-03-20 06:53:17 +00:00
void RageException::CallCleanupHandler( const RString &sError )
{
if( g_CleanupHandler )
g_CleanupHandler( sError );
}
/* This is no longer actually implemented by throwing an exception, but it acts
* the same way to code in practice. */
2006-02-24 03:09:11 +00:00
void RageException::Throw( const char *sFmt, ... )
2002-12-21 08:13:22 +00:00
{
2006-02-14 11:16:39 +00:00
va_list va;
2006-02-24 03:09:11 +00:00
va_start( va, sFmt );
RString error = vssprintf( sFmt, va );
2006-02-14 11:16:39 +00:00
va_end(va);
2002-12-21 08:13:22 +00:00
2006-02-14 11:16:39 +00:00
RString msg = ssprintf(
2006-02-24 03:09:11 +00:00
"\n"
"//////////////////////////////////////////////////////\n"
"Exception: %s\n"
"//////////////////////////////////////////////////////\n"
"",
error.c_str() );
if( LOG )
2002-12-21 18:12:03 +00:00
{
2006-02-24 03:09:11 +00:00
LOG->Trace( "%s", msg.c_str() );
2002-12-21 18:12:03 +00:00
LOG->Flush();
}
2003-02-14 19:00:37 +00:00
else
{
2006-02-24 03:09:11 +00:00
printf( "%s\n", msg.c_str() );
fflush( stdout );
2003-02-14 19:00:37 +00:00
}
2002-12-21 18:12:03 +00:00
2006-09-15 19:40:32 +00:00
#if (defined(WINDOWS) && defined(DEBUG)) || defined(_XDBG) || defined(MACOSX)
2005-05-28 07:29:09 +00:00
if( IsDebuggerPresent() )
DebugBreak();
2002-12-21 08:13:22 +00:00
#endif
if( g_CleanupHandler != NULL )
g_CleanupHandler( error );
exit(1);
2002-12-21 08:13:22 +00:00
}
2004-05-06 00:42:06 +00:00
/*
* Copyright (c) 2001-2004 Chris Danford
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/