You can wrap a simple operation of obtaining an object in a separate function. You can catch the exception:
bool TryGetObject( ExAPI api, int idx, out object obj ) { try { obj = api[idx]; return true; } catch( IndexOutOfBoundsException ) { return false; } }
Then call this function and complete if necessary:
static IEnumerable<object> Iterator( ExAPI api ) { bool abort = false; for( int i = 0; !abort; ++i ) { object obj; if( TryGetObject( api, i, out obj ) ) { yield return obj; } else { abort = true; } } }
Timbo Oct 28 2018-10-28 13:11
source share