Introduce DispatcherUnhandledException
See original GitHub issueIs 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:
- Created a year ago
- Reactions:2
- Comments:6 (5 by maintainers)

Top Related StackOverflow Question
Relatively, this is wrong statement.
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.
In my projects, I listen
DispatcherUnhandledExceptionbut never mark it handled. I just produce some tips and logs. When use Avalonia, I listen theAppDomain.UnhandledExceptioninstead.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
ICommandand handle exception in it.