8000 Catch and rethrow the exception in StylusPlugIn by lindexi · Pull Request #945 · dotnet/wpf · GitHub
[go: up one dir, main page]

Skip to content

Catch and rethrow the exception in StylusPlugIn #945

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

lindexi
Copy link
Member
@lindexi lindexi commented Jun 13, 2019

Adding the try catch in RawStylusInput method that can make the WPF still running when some friend throws an exception in the StylusPlugIn method.

We should not ignore any exception, so I catch it in the Stylus Input thread to make the exception do not break the Stylus Input thread and I rethrow it to the main thread.

This code can make the touch application more stabilize. But the better way is we can control the Stylus Input thread rerun.

See #1037

this code running in Stylus Input thread and this thread is a backgroud thread that will be break when anyone throw an exception in this code
@ghost ghost added the PR metadata: Label to tag PRs, to facilitate with triage label Jun 13, 2019
@ghost ghost requested review from rladuca, vatsan-madhavan, ryalanms and stevenbrix June 13, 2019 15:04
@stevenbrix
Copy link
Contributor

@lindexi is there an issue related to this? i'm trying to understand what this change is doing. From my limited understanding, this sounds like it can break apps that currently depend on how component is handling exceptions.

@stevenbrix
Copy link
Contributor

It also sounds like if we make this change in post 3.0 timeframe that the documentation will need to be updated, correct?

@lindexi
Copy link
Member Author
lindexi commented Jun 21, 2019

@lindexi is there an issue related to this? i'm trying to understand what this change is doing. From my limited understanding, this sounds like it can break apps that currently depend on how component is handling exceptions.

Thanks @stevenbrix . And I will new a issus about it.

@lindexi
Copy link
Member Author
lindexi commented Jun 21, 2019

It also sounds like if we make this change in post 3.0 timeframe that the documentation will need to be updated, correct?

Yes, we should change the StylusPlugIn Class (System.Windows.Input.StylusPlugIns) document and remove this word If you use a StylusPlugIn inside a control, you should test the plug-in and control extensively to make sure they do not throw any unintended exceptions. , because now we can still run when the app code throws an exception in StylusPlugIn method

@rladuca rladuca added the not-right-now metadata: PRs/Issues thar are not being considered at the moment label Jul 4, 2019
@rladuca rladuca modified the milestones: Future, 5.0 Jul 4, 2019
@stevenbrix
Copy link
Contributor

because now we can still run when the app code throws an exception in StylusPlugIn method

Well you still would need to handle the exception in your UnhandledException handler, right? This won't magically make things resilient to the StylusPlugin throwing exceptions will it?

@stevenbrix
Copy link
Contributor

@lindexi, this is a better proposed solution than #936

Can you provide some screenshots of what the caught exception looks like? Does it contain the inner exception with the original callstack?

@stevenbrix
Copy link
Contributor

I'm also curious to know if this is something that other community members think is a good idea. It seems reasonable to me, but I'm wondering if there are other, more full featured solutions that could possibly cover other scenarios as well.

On #936, @weltkante brought up how WinForms has Application.SetUnhandledExceptionMode. Would something like that apply here?

I'm certainly not trying to discount this effort done here, just want to make sure we are thorough and design the right thing :)

/cc @dotMorten

@dotMorten
Copy link
Contributor
dotMorten commented Oct 4, 2019

Thanks for the mention. If I understand this issue correctly, I'm concerned there's even an exception being thrown here, whether it's in the background or moved to the main-thread. IMHO the problem is still there, because I can't handle the unhandled exception (unless I put in an unhandled exception handler which IMHO is nothing but a band-aid). It's basically just an exception waiting to kill your app regardless.

Instead, I think first the proper fix would be to ensure this code doesn't throw, so there's nothing to catch. I'm hoping that's possible. In the event that there isn't, it means it's an expected exception, and it should IMHO just be dealth with the right way and swallowed. At no point should an exception be thrown that the user can't directly guard against in a try/catch around a method call (since it's an event, there is nothing to try/catch).

Looking at the example in the linked issue, IMHO the proper fix here is to fix the stylus plug-in. That code shouldn't throw, but just catching and swallowing it would mean the developer would never know their plugin was bad.

@stevenbrix
Copy link
Contributor

IMHO the problem is still there, because I can't handle the unhandled exception (unless I put in an unhandled exception handler which IMHO is nothing but a band-aid). It's basically just an exception waiting to kill your app regardless.

Yeah this is sort of my thought, but I don't think you can always catch all StylusPlugIn exceptions. I'm sure there are scenarios where it's fundamentally not possible if you are using a 3rd party library and maybe they contain a StylusPlugin and do some stuff with it. And in your app you never use it directly? You could test as much as you want, but a component could always throw an exception in some case you aren't aware of.

I'm hoping that's possible. In the event that there isn't, it means it's an expected exception, and it should IMHO just be dealth with the right way and swallowed. At no point should an exception be thrown that the user can't directly guard against in a try/catch around a method call (since it's an event, there is nothing to try/catch).

If it's in the UnhandledException handler, you can set it to handled so that the app doesn't crash, correct?

Looking at the example in the linked issue, IMHO the proper fix here is to fix the stylus plug-in. That code shouldn't throw, but just catching and swallowing it would mean the developer would never know the plugin was bad.

This is a very trivial case, it would be great to see a more complicated scenario where this makes more sense (if one exists).

I also want to think of what the end-user experience is here. Do we want apps to crash just because a stylus plugin threw an exception? What if I'm writing a document with a pen and oops, the stylus stopped working, ok i'll just type. I'd prefer every WPF app be robust by default in this scenario, rather than leave this responsibility to the app developer. When apps crash like that users think it's an issue with Windows, and they are partially correct because we should be preventing scenarios like that if it's possible the app can continue functioning in a usable way. Let the user manually close the app if something becomes so broken. But I also don't know what swallowing exceptions here does, is it possible to recover the Stylus and get it to continue working?

@rladuca
Copy link
Member 8000
rladuca commented Oct 4, 2019

If an exception in a StylusPlugin didn't kill the Stylus thread the rest of the application would, generally, function well. There could be some erroneous behavior that is application specific, but not framework specific. For instance, if the application was using a plugin to limit stylus input to a specific area, then a failure in a plugin could then expand the input area unintentionally.

This sort of application specific consequence can be handled if we maintain the ability to get the errors that are arising and react to them. Why not provide a (ThreadStatic) event in StylusPlugin for error trapping and let the application developer decide what to do with them? If the error isn't marked as handled after the event handlers are called, allow the exception to crash the Stylus thread (for compat reasons).

It feels like we should be having this sort of design discussion in the issue, and not in a PR. I suggest continued discussion move over to there.

@stevenbrix
Copy link
Contributor

It feels like we should be having this sort of design discussion in the issue, and not in a PR. I suggest continued discussion move over to there.

Fair point, I'll continue the discussion there

Base automatically changed from master to main March 17, 2021 17:38
@ryalanms ryalanms requested a review from a team as a code owner March 17, 2021 17:38
@ryalanms ryalanms modified the milestones: 5.0.0, 7.0.0 Aug 26, 2021
@pchaurasia14 pchaurasia14 added the Community Contribution A label for all community Contributions label Jul 20, 2022
@ghost ghost assigned lindexi Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community Contribution A label for all community Contributions not-right-now metadata: PRs/Issues thar are not being considered at the moment PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0