Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • This seems to lose the fallback behavior that was inherent in the question. Commented Dec 22, 2022 at 17:42
  • @JimmyJames I agree. Without the context of what the sample code actually does, it's hard to know. I would posit that fallback isn't the only solution. Commented Dec 22, 2022 at 18:04
  • I thought it was pretty clear that the OP was trying to avoid duplication as a result of the need to call B in the both the case that A isn't applicable and if A failed. The call to C is only shown as a fallback. In general, you can't protect against exceptions in a pre-check. For example, an IO error must be handled at the time of the call. Commented Dec 22, 2022 at 19:12
  • That is very likely the case. I removed the assumption that it was necessary in this solution since yours already covered that. Commented Dec 22, 2022 at 19:37