Hopefully you can all handle the
VB.NET without feeling too dirty! :-)
I have a WPF application, .NET 4.5.2, ReactiveUI v6.4.0.1 from NuGet. I am trying to handle exceptions thrown by my commands. This works OK when my command is triggered by a button click, but I also want to execute the command when my view is loaded. Here's the basic setup:
ViewModel constructor:
Me.FetchData = ReactiveCommand.CreateAsyncTask(
Async Function(x)
Return Await FunctionThatThrowsAnException()
End Function )
Me.FetchData.ToProperty(Me, Function(x) x.MyData, _myData)
' Just an example of error handling, will use UserError and handle in view...
Me.FetchData.ThrownExceptions.Subscribe(
Sub(ex) Me.Log().ErrorException(ex.Message, ex)
)' I've also tried this here...
'Me.FetchData.ExecuteAsync().Subscribe()
View constructor:
Me.WhenAnyValue(
Function(x) x.ViewModel.FetchData
).SelectMany(
Function(x) x.ExecuteAsync()
).Subscribe()
The result is that the exception is thrown, the log message (from the ThrownExceptions handler) is printed, and the application terminates. If I remove the ExecuteAsync call from the view constructor, and just click the button to fetch the data (bound to the same command), then the message is printed and the application stays running.
So, what am I missing about handling ThrownExceptions when calling ExecuteAsync? Please point out anything else the indicates I haven't a clue, since I am really struggling to grok ReactiveUI at this point!
Thanks!
Mark