ExceptionDispatchInfo CleanupAndGetThrower() { if (_finalActions != null) { _finalActions(); } SpecReporter.Add(this); ConsoleOutcomePrinter.PrintOutcomes(this); //rethrow the first error if any return(Outcomes.Select(x => x.ExceptionDispatchInfo).FirstOrDefault(x => x != null)); }
void CleanupAndThrowIfFailed() { finalActions?.Invoke(); SpecReporter.Add(this); ConsoleOutcomePrinter.PrintOutcomes(this, WriteLine); //rethrow the first error if any var thrower = Outcomes.Select(x => x.ExceptionDispatchInfo).FirstOrDefault(x => x != null); thrower?.Throw(); //check if there were any un-inspected exception references var unInspectedExceptionReference = caughtExceptionReferences .Where(x => !x.Key.IsValueCreated) .Select(x => x.Value) .FirstOrDefault(); if (unInspectedExceptionReference != null) { throw new Exception($"Error was thrown by step \'{unInspectedExceptionReference.Description}\', but was not inspected"); } }