Original Post
Do you generally prefer to use exceptions or error codes in your games/apps? And why? For example, if I have a malloc wrapper... ...vs... In the first version, an exception will be thrown if malloc failed. I would probably not handle this exception, as I would make tons of calls to this function, so the program would crash, and I could get a stack trace from the debugger. In the second version, the program would run until it crashes due to an access violation. The location of the error would be harder to trace, but if malloc fails, I'm probably doing something completely wrong in the first place. And another case: ...vs... In this example, it would work just fine either way, as long as the ExConversion is handled when using the first. These may not be the best examples. What I would like to know is when exceptions are the absolute best way to handle errors. If they can easily be avoided with little cost, I may not use them at all in my current project. Any help is appreciated. EDIT: This is hypothetical code. I don't actually use malloc in C++ code. [Edited by - Daggerbot on December 11, 2008 8:17:12 PM]
static void* MyAlloc( uint size )
{
register void* result = ::malloc( size );
if( result == nullptr )
throw ExAllocation();
}
static void* MyAlloc( uint size )
{
return ::malloc( size );
}
template< typename I, typename C >
static I ConvertStringToInt( const C* string )
{
if successful
return result;
else
throw ExConversion( Integer::GetProperties()->ToString() );
}
template< typename I, typename C >
static bool ConvertStringToInt( const C* string, I* out )
{
if successful
{
*out = result;
return true;
}
else
return false;
}