I wanted to know how to handle exceptions in my Webview, because sometimes the site is off, and the page does not load, and sometimes crashes the application. I tried a try
catch
on load, but it does not enter the exception, I want it when the server is off, it sends the message, SERVER UNAVAILABLE!
See my Webview:
public void carregarSite() {
// Verifica conexão
if (verificaConexao()) { //se tiver conexao
// Ajusta algumas configurações
WebSettings ws = wv.getSettings();
ws.setJavaScriptEnabled(true);
ws.setBuiltInZoomControls(true);
wv.setWebViewClient(new WebViewClient());
wv.setWebChromeClient(new WebChromeClient());
try{
wv.loadUrl(URL);
} catch(Exception e){
Toast.makeText(Main.this, "SERVIDOR INDISPONIVEL!", 1000).show();
}
} else
msgConexao(); // metodo de msg de conexao
}