question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Introduce DispatcherUnhandledException

See original GitHub issue

Is your feature request related to a problem? Please describe. Currently, we have to catch exceptions on event handler level to control an execution flow, thus duplicating same code all over the project.

Describe the solution you’d like Anything similar to https://docs.microsoft.com/en-us/dotnet/api/system.windows.application.dispatcherunhandledexception?redirectedfrom=MSDN&view=windowsdesktop-6.0

Additional context As an example of the problem, consider different parts of our application randomly throws PayToExecuteException() and we want to catch it to show a suggestion to pay to the user. In WPF we can subscribe to DispatcherUnhandledException and provide the logic once. In Avalonia, currently, we either have to catch the exception in each of the event handler, or replace the exception with return/if logic thus increasing the codebase.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
jinekcommented, Jul 1, 2022

Relatively, this is wrong statement. image

In fact one can know whether exception has been handled correctly. There is no big difference when catching exception on first level up the stack or second or third etc. If Avalonia has issues properly handling the exceptions, that should be addressed and fixed, for example, with try/finally constructions how they are intended to be. Absence of such handler in the loop assumes that we have to duplicate same catch block to several places.

As one more example, consider that we have introduced OperationDeclinedException() which we throw whenever an user cancel dialogs, operations etc. With current approach we have to duplicate same catch(OperationDeclinedException){ // doing nothing } all over our event handlers which starts user operation. Once we want to change that or introduce anything new, we have to fix all this N places. And important thing here is that when number of features grows to infinity, number of this N duplicates also becomes infinity. Alternatively, having global handler it always stays constantly 1.

1reaction
yll690commented, Jul 1, 2022

In my projects, I listen DispatcherUnhandledException but never mark it handled. I just produce some tips and logs. When use Avalonia, I listen the AppDomain.UnhandledException instead.

If the exception only indicate some user operation is failed, we can actually give user a tip and ignore them. In this case, I defined a custom implement of ICommand and handle exception in it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Application.DispatcherUnhandledException Event
Occurs when an exception is thrown by an application but not handled.
Read more >
wpf c# DispatcherUnhandledException not firing
I am in the process of creating a new WPF application and wanted to implement the DispatcherUnhandledException handler.
Read more >
DispatcherUnhandledException
UnhandledException in Windows form: when an exception is not caught by an event handler within the application thread or within the current appdomain,...
Read more >
Handling exceptions in WPF
This is done through the DispatcherUnhandledException event on the Application class. If subscribed to, WPF will call the subscribing method once an ...
Read more >
Unhandled Exception Handler For WPF Applications
The DispatcherUnhandledException is called whenever the UI thread of the application generated an unhandled exception.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found