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

Throw exception when Focus() fails. #16821

Closed
mateli opened this issue Aug 27, 2024 · 2 comments
Closed

Throw exception when Focus() fails. #16821

mateli opened this issue Aug 27, 2024 · 2 comments
Labels

Comments

@mateli
Copy link

mateli commented Aug 27, 2024

Describe the bug

When calling Focus() from the constructor or OnInitialized it silently fails with weird behavior.

Also when calling Focus when a component or it's parent component has IsVisible == false this silently fails.

To Reproduce

Call Focus() from constructor, OnInitialized or when the component/parent is disabled.

Expected behavior

When Focus() cannot be performed an Exception should be thrown.

Avalonia version

11.1.3

OS

No response

Additional context

No response

@mateli mateli added the bug label Aug 27, 2024
@AvaloniaUI AvaloniaUI deleted a comment Aug 27, 2024
@maxkatz6
Copy link
Member

Focus method returns a boolean indicating operation result. It would be very wasteful to throw an exception every time.

@maxkatz6 maxkatz6 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 27, 2024
@mateli
Copy link
Author

mateli commented Aug 28, 2024

If focus() or any other function fail because it is run to early this is 100% a bug and an exception makes sure that the developers are informed of the bug. Correct usage will not cause an exception. Also if focus() can fail for more than one reason how do I know that reason from getting a boolean?

And even if so to me exceptions are way more clean than requiring testing with if's. Getting to collect error handling into a single try...catch is one of the beautiful things with C#. Especially as one need to surround code with try...catch statements anyway means that handling another error doesn't produce more error handling code.

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

No branches or pull requests

3 participants
@mateli @maxkatz6 and others