Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should it be possible to have multiple fallbacks #507

Open
NottyCode opened this issue Jan 24, 2020 · 5 comments
Open

Should it be possible to have multiple fallbacks #507

NottyCode opened this issue Jan 24, 2020 · 5 comments

Comments

@NottyCode
Copy link
Member

With the update to Fallbacks to support triggering on particular exceptions it makes me wonder if it would be useful to support multiple Fallbacks on a method so different exceptions can trigger different fallback behaviour.

Something like:

@Fallbacks(@Fallback(fallbackMethod="fallbackOnIOE", applyOn=IOException.class),
           @Fallback(fallbackMethod="fallbackOnNPE", applyOn=NullPointerException.class))
public boolean doStuff() throws IOException, NullPointerException {
   // do stuff
}
@Ladicek
Copy link
Contributor

Ladicek commented Jan 24, 2020

In the FallbackHandler, you have access to the causing exception via ExecutionContext.getFailure, which should be enough for this niche usecase IMHO.

@Emily-Jiang
Copy link
Member

Emily-Jiang commented Feb 4, 2020

@Ladicek the FallbackHandler cannot access the same instance of the method residing. In order to provide the simpler model, we could do the following:

@Fallback(fallbackMethod="fallbackOnIOE", applyOn=IOException.class)
@Fallback(fallbackMethod="fallbackOnNPE", applyOn=NullPointerException.class)

public boolean doStuff() throws IOException, NullPointerException {
   // do stuff
}

This is very simple. We just need to make Fallback annotation to be Repeatable. Thoughts?

@Ladicek
Copy link
Contributor

Ladicek commented Feb 4, 2020

the FallbackHandler cannot access the same instance of the method

Can it not inject it? Sure, then it wouldn't be able to access private methods...

@Fallback(fallbackMethod="fallbackOnIOE", applyOn=IOException.class)
@Fallback(fallbackMethod="fallbackOnNPE", applyOn=NullPointerException.class)

public boolean doStuff() throws IOException, NullPointerException {
   // do stuff
}

This is very simple.

This is not "very simple". What happens when the exception matches multiple fallback annotations? First matching wins? Last matching wins? Most specific wins?

Frankly, I'd consider more interesting to somehow let the fallback method access the causing exception.

I still consider this a niche case, though. In my opinion, fallback doesn't typically depend on the thrown exception, but on the method in question.

@Emily-Jiang
Copy link
Member

We discussed this further at today's hangout with @Ladicek @Azquelt @Joseph-Cass , the concern with the matching orders from @Ladicek is difficult to handle. With this, since FallbackHandler is designed for advanced users and can handle this use case, we will not attempt to introduce another way to do the same thing. @NottyCode what do you think?

@Ladicek
Copy link
Contributor

Ladicek commented Mar 3, 2020

I'd personally close this issue, because I really don't want to create another syntax for try/catch/finally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants