Caliburn.Micro icon indicating copy to clipboard operation
Caliburn.Micro copied to clipboard

Frame based navigation OnActivateAsync and exceptions

Open enrico-padovani opened this issue 4 years ago • 3 comments

If an Exception occurs inside OnActivateAsync the view gets activated anyway.

What is the recommended way to handle exceptions inside OnActivateAsync?

Thanks, Enrico

enrico-padovani avatar May 10 '21 09:05 enrico-padovani

OnActivateAsync is a place to run code before the View is shown. For example, you could get data from a database or web service to display to a user. I would use a try catch block to handle any exceptions that may occur in the OnActivateAsync. If an exception does happen, I would show the user an error message.

What are you expecting to happen?

vb2ae avatar May 16 '21 01:05 vb2ae

I was expecting it to cancel the navigation and call Deactivate. I understand now that this is by design and It's also related to my other issue.

I'd need to modify my code and check if I can navigate to a vm before activating it. Right?

enrico-padovani avatar May 16 '21 07:05 enrico-padovani

I'm using Aurelia (another Rob's creature) for web solutions and the router has an elegant way to allow vm to be activated: https://aurelia.io/docs/api/router/interface/RoutableComponentCanActivate/method/canActivate/ maybe some idea to bring to Caliburn Micro.

enrico-padovani avatar May 19 '21 19:05 enrico-padovani