Forum Xamarin.Forms

How to handle errors in WebView

vivaanmathurvivaanmathur Member ✭✭
edited May 2019 in Xamarin.Forms

I'm developing an app for my client and have configured a WebView in my Xamarin.forms application. How do I handle errors (like Address Unreachable, no internet, etc..)

I have added try clause and catch exception. But it doesn't work and the default unreachable page comes on android and a blank page on iOS if there is no Internet

try{WebView.Source = "";}
catch (Exception){var htmlSource = new HtmlWebViewSource();
htmlSource.Html = @"

An Error!!!!

Could not be loaded

WebView.Source = htmlSource;}
I expect "This page could not be loaded" but instead I see the original android error page: "net::ERR_ADDRESS_UNREACHABLE"

BTW - I had to put cuz forum was not letting me put links... and An Error!!!! is in H1, but it loaded incorrectly (rendered on the forum itself?


Best Answers


  • vivaanmathurvivaanmathur Member ✭✭

    Oh thank you so much!!! This one is so much better than Stack Over Flow who dont answer questions forever


Sign In or Register to comment.