How do I do error handling on Jsoup when the program fails to connect to the website?
For example that the website doesn't exist and I would like to print error message to the user
The code below shows the way I connected to a certain website but what I want is that if the website doesn't exist, I wanted it to print error messages.
Document doc;
try {
// need http protocol
doc = Jsoup.connect("https://forum.lowyat.net/user/OldSchoolJoke").get();
// get page title
String title = doc.title();
//System.out.println("title : " + title);
// get all links
Elements links = doc.select("div.postdetails");
for (Element link : links) {
// get the value from href attribute
System.out.println("\nlink : " + link.attr("div"));
System.out.println("text : " + link.text());
}
} catch (IOException e) {
e.printStackTrace();
}