The title is a bit vague so I'll try to elaborate.
I have a function
makeFoo(int bar) -> returns Foo or throws Exception.
I also have a batch version of this
makeFoos(int bars) -> returns Foo
which basically loops through bars and runs makeFoo() on them.
Issue is, if while running makeFoos(), makeFoo() throws an Exception, what do I do? I don't want to break out of makeFoos() because I want to continue processing the rest of the bars. But also, I want to retain the Exception that was thrown.
My initial solution is, instead of returning Foo, I return Result<Foo>. Where Result is a wrapper class:
class Result<T>: T data; Exception e;
Is there a better way that I can approach this?
Edit: Apologies if this is considered a duplicate post, but I posted a more general version of this question here: Result Object vs. Exceptions