I think I found a situation where the RescueAttribute is broken. Or maybe I'm misusing soklokalnye procedures.
I have a ViewModel like this:
[Rescue("Rescue")] class MyViewModel {
AsyncResult is implemented as follows:
using Exec = Caliburn.PresentationFramework.Invocation.Execute; public class AsyncResult : IResult { private readonly Action _function; public AsyncResult(Action function) { _function = function; } public void Execute(ResultExecutionContext context) { Exec.OnBackgroundThread(delegate { try { _function(); } catch (Exception exc) { Exec.OnUIThread(() => Completed(this, new ResultCompletionEventArgs { Error = exc, WasCancelled = true })); return; } Exec.OnUIThread(() => Completed(this, new ResultCompletionEventArgs())); }); } public event EventHandler<ResultCompletionEventArgs> Completed = delegate { }; }
If I uncomment the exception in my ViewModel above, Rescue will not be able to handle the exception.
Is this a bug in Caliburn, or is AsyncResult implemented incorrectly?
If you throw an exception before exiting to return AsyncResult, Rescue works fine. Also, if an exception is thrown in an asynchronous stream, recovery still works!
EDIT: You can also use Show.MessageBox instead of AsyncResult to reproduce the same issue.
source share