New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XF: NavigationService swallowing Exceptions #1024
Comments
Are you sure they are swallowed? Are they just not being caught? If I await and wrap navigation in a try/catch I get the exceptions. Can you reproduce an instance where that is not the case? |
The scenario is: protected override void OnInitialized()
{
NavigationService.NavigateAsync("MainPage");
} I believe you are correct actually, it's more that the task swallows the exception resulting in the only exception the dev sees being no page. This is more of a thought that we could improve the logging within the framework so that it is easier for dev's to see what happened without having to throw in a try catch every 10 lines. |
We should probably update the templates to provide guidance on this. Maybe update the app to this:
|
We could also add an event handler to catch unhandled exceptions and add a virtual method in the base class so they can be overridden
|
We could also log more in the NavigationService. I mean we have the logger there. Might as well use it. |
Actually I think your idea of adding a TaskScheduler.UnobservedTaskException handler may be the way to go there. Also yes we do have the logger in the NavigationService, we should probably use it more, especially with how critical Navigation is. |
We could actually reset the Application.MainPage to an instance of a new ContentPage that contains the error message by default. Do you think this would be too intrusive, or a good thing to help developers? |
In short yes, I do think we should provide a mechanism for introducing an error page so that you don't end up with an app crash because no page was pushed onto the stack. I'm not sure though if I prefer introducing an interface specifically for failed navigation handling or if we should incorporate it as part of a larger Either way I would say we should probably introduce the page by providing a default View/ViewModel in Prism.Forms that can be registered for Navigation by PrismApplication and then updated by a dev if they provide their own View with a key like |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
When there is some sort of initialization Exception being thrown the NavigationService is swallowing the exception leaving the dev to wonder what on earth happened. When this occurs on the initial page, the app will crash when no page is pushed resulting in an even more confusing error since we have no real idea why the Page never loaded.
This should be fixed by a two prong approach:
PrismApplicationBase
likeEnableViewModelLocatorLogging
. Another possibility would be to introduce a virtual method inPrismApplicationBase
that we could pass any exceptions to and the dev could then have full control of how they want to log the exception.The text was updated successfully, but these errors were encountered: