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

[Enhancement] Add Exception Handler to DelegateCommand #2873

Closed
dansiegel opened this issue May 26, 2023 · 0 comments · Fixed by #2887
Closed

[Enhancement] Add Exception Handler to DelegateCommand #2873

dansiegel opened this issue May 26, 2023 · 0 comments · Fixed by #2887

Comments

@dansiegel
Copy link
Member

Summary

Currently there is no good way to handle exceptions from DelegateCommand. This is particularly problematic for DelegateCommand<T> where the framework (i.e. Xamarin.Forms) may send an invalid type by default. As there is no way to handle this it renders the DelegateCommand unusable.

API Changes

Update DelegateCommand to have both a Generic and non-Generic Catch method. In the event that an error is encountered we will internally catch the exception and either rethrow the exception if no delegate handler is provided, otherwise we will pass the exception to the provided handler.

MyCommand = new DelegateCommand(OnMyCommandExecuted)
    .Catch<SomeException>(ex => {
        // handler with ex cast as SomeException
    })
    .Catch(ex => {
        // handler with generic Exception type
    })

Intended Use Case

This will generally help to allow the reuse of common code blocks for handling errors across multiple Commands.

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

Successfully merging a pull request may close this issue.

1 participant