Catch all the exception in touch process This MR do not expect to merge#936
Catch all the exception in touch process This MR do not expect to merge#936lindexi wants to merge 1 commit intodotnet:masterfrom
Conversation
Because we can not use any way to repair it when the code throw the exception and the Stylus Input thread will exitt
|
I'd prefer bugs being fixed instead of being ignored. If you ignore the exceptions they will never get fixed. It just leads to problems of the type "my touch input stops responding" because the thread may be in a state it can't recover from and just keeps throwing and ignoring exceptions. If the WPF team really wants a catch-all handler it should have associated diagnostics and not just ignore the exception. Personally I have my own top level exception handlers on AppDomain, Dispatcher, Application etc. to report (and potentially ignore) unhandled exceptions. I believe the option to ignore exceptions from which it cannot recover should be left to the application programmer, not be made at the framework level. For example WinForms has Application.SetUnhandledExceptionMode to assist with this problem. |
| } | ||
| catch (Exception) | ||
| { | ||
| // If the code above throw an exception that the Stylus Input thread will be break. And we can not use any way to repair it. |
There was a problem hiding this comment.
Some grammar issues.
// If the code above throws an exception the Stylus Input thread will break and there is nothing we can do to repair it.| catch (Exception) | ||
| { | ||
| // If the code above throw an exception that the Stylus Input thread will be break. And we can not use any way to repair it. | ||
| // Maybe only some touch device be crash but other touch device can run still. |
There was a problem hiding this comment.
Only some of the touch devices may crash and the others can still run normally.
| { | ||
| // If the code above throw an exception that the Stylus Input thread will be break. And we can not use any way to repair it. | ||
| // Maybe only some touch device be crash but other touch device can run still. | ||
| // To catch all the exception to make the application can run when the code throw an exception. |
There was a problem hiding this comment.
We catch all the exceptions so that the application can still be alive.
|
@weltkante I think the better way is to offer some way to restart the Stylus Input thread or some way to reset the status |
|
@weltkante You mean that we'd better unload the touch module and then initialize it again during the We have some other similar situations that reinitializing can fix stylus issues such as these below:
The codes that cause the issues are different but reinitializing the whole stylus module can fix them. |
@weltkante The user can only fix it by reboot the device when the fullscreen application running in the device which only supports touch input. The application stops responding to touch input is an important crash for the touch application. But I must admit that this is not a good way and it is an evil code. We should not ignore the exception. |
|
In my opinion WPF needs to deal gracefully with hardware devices being (un)plugged or becoming unusable. If it can't do that I prefer an application crash (usually surfaced via unhandled exceptions) over stopping to respond, so I can bring up a diagnostic interface to report the problem to our support. Our customers usually have support contracts and if they have faulty devices preventing proper usage of our software we may be able to root cause the problem this way. If the input just stops working this is much harder to diagnose on our side and the customer isn't any more happy either. I undestand not everyone wants that, thats why I brought up the option of configurable top level exception handling, like WinForms allows in Application.SetUnhandledExceptionMode. I don't know if WPF already has a similar setting. If you want to ignore exceptions you can't recover from, you'll have to give the application the chance to abort (or restart) the whole program.
If this is guaranteed to fix the problem you can do that. But what if the device is broken and you end up an infinite loop of ignoring exceptions? I don't want to burn a CPU core at 100% just repeatedly ignoring the same exception. |
|
This MR may fix the problem that some friend throws an exception in StylusPlugIn. Just like this code. The code will break the Stylus Input thread. The OnStylusDown running in Stylus Input thread and if some friend throws any exceptions that will break the thread. And the application will stop responding touch. Of course, the actual situation may be more complicated. Maybe some of my friends just didn't realize that the code he wrote was unstable. But add But I do not think we can throw any unintended exceptions in StylusPlugIn. See StylusPlugIn Class (System.Windows.Input.StylusPlugIns)
See Intercepting Input from the Stylus
|
|
@weltkante @walterlv @lindexi thank you for the great discussion on this PR! My personal feeling on this issue, and I think there is consensus on this thread, is that catching all exceptions and ignoring them is not the right fix for this issue. As for something analogous to the |
|
Thank you @stevenbrix . The core issue is how to fix the touch break when some core throw an exception in the stylus plugin method. Maybe it is the WPF StylusPlugIn API lack a little design. But I do not know how to fix the design. It will break the stylus input thread when we do not capture the StylusPlugIn exception, so I do not think we can use Do you mean to use ExceptionDispatchInfo to capture the exception and rethrow? See Catch and rethrow the exception in StylusPlugIn by lindexi · Pull Request #945 · dotnet/wpf |
Makes sense since that only catches exceptions on the UI thread.
@lindexi, that is definitely a better overall solution. Let's continue the discussion on that PR. Do you mind if close out this PR? |
Because we can not use any way to repair it when the code throw the exception and the Stylus Input thread will exit
Maybe it can fix #935
It is an evil code