exceptions

This commit is contained in:
Glenn Maynard
2004-12-01 01:11:14 +00:00
parent c41cefe7fd
commit 318a27fcab
3 changed files with 26 additions and 63 deletions
+2 -19
View File
@@ -4,20 +4,12 @@
#include "RageLog.h" #include "RageLog.h"
#include "StepMania.h" #include "StepMania.h"
#include <cstdarg>
#if defined(_WINDOWS) && defined(DEBUG) #if defined(_WINDOWS) && defined(DEBUG)
#include <windows.h> #include <windows.h>
#endif #endif
RageException::RageException( const CString &str ):
m_sError(str)
{
}
const char* RageException::what() const throw ()
{
return m_sError;
}
/* This is no longer actually implemented by throwing an exception, but it acts /* This is no longer actually implemented by throwing an exception, but it acts
* the same way to code in practice. */ * the same way to code in practice. */
void RageException::Throw(const char *fmt, ...) void RageException::Throw(const char *fmt, ...)
@@ -52,15 +44,6 @@ void RageException::Throw(const char *fmt, ...)
HandleException( error ); HandleException( error );
} }
void RageException::ThrowNonfatal(const char *fmt, ...)
{
va_list va;
va_start(va, fmt);
CString error = vssprintf( fmt, va );
va_end(va);
throw RageException( error );
}
/* /*
* Copyright (c) 2001-2004 Chris Danford * Copyright (c) 2001-2004 Chris Danford
* All rights reserved. * All rights reserved.
+2 -18
View File
@@ -5,25 +5,9 @@
#ifndef RAGEEXCEPTION_H #ifndef RAGEEXCEPTION_H
#define RAGEEXCEPTION_H #define RAGEEXCEPTION_H
#include <exception> namespace RageException
#include <cstdarg>
class RageException : public exception
{ {
public: void NORETURN Throw(const char *fmt, ...);
RageException( const CString &str );
virtual const char *what() const throw();
virtual ~RageException() throw() { }
/* The only difference between these is that Throw triggers debug behavior
* and Nonfatal doesn't. Nonfatal is used when the exception happens
* normally and will be caught, such as when a driver fails to initialize. */
static void NORETURN Throw(const char *fmt, ...);
static void NORETURN ThrowNonfatal(const char *fmt, ...);
protected:
CString m_sError;
}; };
#endif #endif
+22 -26
View File
@@ -111,47 +111,43 @@ RageSoundDriver *MakeRageSoundDriver(CString drivers)
for(unsigned i = 0; ret == NULL && i < DriversToTry.size(); ++i) for(unsigned i = 0; ret == NULL && i < DriversToTry.size(); ++i)
{ {
try { Driver = DriversToTry[i];
Driver = DriversToTry[i]; LOG->Trace("Initializing driver: %s", DriversToTry[i].c_str());
LOG->Trace("Initializing driver: %s", DriversToTry[i].c_str());
#ifdef _WINDOWS #ifdef _WINDOWS
if(!DriversToTry[i].CompareNoCase("DirectSound")) ret = new RageSound_DSound; if(!DriversToTry[i].CompareNoCase("DirectSound")) ret = new RageSound_DSound;
if(!DriversToTry[i].CompareNoCase("DirectSound-sw")) ret = new RageSound_DSound_Software; if(!DriversToTry[i].CompareNoCase("DirectSound-sw")) ret = new RageSound_DSound_Software;
if(!DriversToTry[i].CompareNoCase("WaveOut")) ret = new RageSound_WaveOut; if(!DriversToTry[i].CompareNoCase("WaveOut")) ret = new RageSound_WaveOut;
#endif #endif
#ifdef _XBOX #ifdef _XBOX
if(!DriversToTry[i].CompareNoCase("DirectSound")) ret = new RageSound_DSound; if(!DriversToTry[i].CompareNoCase("DirectSound")) ret = new RageSound_DSound;
#endif #endif
#ifdef HAVE_ALSA #ifdef HAVE_ALSA
if(!DriversToTry[i].CompareNoCase("ALSA")) ret = new RageSound_ALSA9; if(!DriversToTry[i].CompareNoCase("ALSA")) ret = new RageSound_ALSA9;
if(!DriversToTry[i].CompareNoCase("ALSA-sw")) ret = new RageSound_ALSA9_Software; if(!DriversToTry[i].CompareNoCase("ALSA-sw")) ret = new RageSound_ALSA9_Software;
#endif #endif
#ifdef HAVE_OSS #ifdef HAVE_OSS
if(!DriversToTry[i].CompareNoCase("OSS")) ret = new RageSound_OSS; if(!DriversToTry[i].CompareNoCase("OSS")) ret = new RageSound_OSS;
#endif #endif
#ifdef RAGE_SOUND_CA #ifdef RAGE_SOUND_CA
if(!DriversToTry[i].CompareNoCase("CoreAudio")) ret = new RageSound_CA; if(!DriversToTry[i].CompareNoCase("CoreAudio")) ret = new RageSound_CA;
#endif #endif
#ifdef RAGE_SOUND_QT1 #ifdef RAGE_SOUND_QT1
if(!DriversToTry[i].CompareNoCase("QT1")) ret = new RageSound_QT1; if(!DriversToTry[i].CompareNoCase("QT1")) ret = new RageSound_QT1;
#endif #endif
if(!DriversToTry[i].CompareNoCase("Null")) ret = new RageSound_Null; if(!DriversToTry[i].CompareNoCase("Null")) ret = new RageSound_Null;
if( ret == NULL ) if( ret == NULL )
{ {
LOG->Warn( "Unknown sound driver name: %s", DriversToTry[i].c_str() ); LOG->Warn( "Unknown sound driver name: %s", DriversToTry[i].c_str() );
continue; continue;
} }
CString sError = ret->Init(); CString sError = ret->Init();
if( sError != "" ) if( sError != "" )
{ {
LOG->Info( "Couldn't load driver %s: %s", DriversToTry[i].c_str(), sError.c_str() ); LOG->Info( "Couldn't load driver %s: %s", DriversToTry[i].c_str(), sError.c_str() );
SAFE_DELETE( ret ); SAFE_DELETE( ret );
}
} catch(const RageException &e) {
LOG->Info("Couldn't load driver %s: %s", DriversToTry[i].c_str(), e.what());
} }
} }