RxCommand.ThrownExceptions encourages awkward exception marshalling
Hi,
I wonder if I'm doing it wrong or if this is a genuine API shortcoming...
I typically have a base exception type from which all the recoverable exceptions that my app produces derive. Any other exceptions should be marshalled to the UI thread and then be allowed to crash the app, with a top-level exception handler doing some logging first.
When subscribing to ThrownExceptions, you end up having to check the type of the exception, everywhere, and then possibly rethrow on the UI thread manually. Subscribing to the exceptions is pretty much mandatory, and then filtering/rethrowing is easy to forget, which makes it easy to leave your app alive and in some unpleasant undefined state.
How about a handy extension method:
public static ThrownExceptionsOf<TException>(this IHandleObservableErrors This)
where TException : Exception
{
return This.ThrownExceptions.SelectMany(ex => {
if (typeof(TException).IsAssignableFrom(ex.GetType())) {
return Observable.Return((TException)ex);
}
return Observable.Empty<TException>()
}
}