Which of the subclasses of IOException are more probably to be thrown?
I want throw (IOException) for this program. But I don’t know which of the subclasses of IOException are more likely to be thrown by this program. How should I identify?
Code Java:
import java.io.*;
import java.net.*;
import java.util.ArrayList;
public class SimpleSpider
{
ArrayList<String> set = new ArrayList<String>();
public void search(String host)
{
try
{
URL u = new URL(host);
set.add(host);
ArrayList<String> tags = Util.extractTags(u);
for (int i = 0; i < tags.size(); i++)
{
String nexthost = Util.extractURL(tags.get(i));
if (nexthost != null && !set.contains(nexthost))
{
System.out.println(nexthost);
search(nexthost);
}
}
}
catch (IOException e) {}
}
public static void main (String[] args)
{
SimpleSpider spider = new SimpleSpider();
spider.search("http://en.origami-club.com/");
}
}
Re: Which of the subclasses of IOException are more probably to be thrown?
Quote:
don’t know which of the subclasses of IOException are more likely to be thrown by this program
Read the API doc for each of the classes inside the try{}catch() block to see what they can throw.
Re: Which of the subclasses of IOException are more probably to be thrown?
I read the API. I think the most likely to be thrown is : EOFException, InterruptedIOException, UnknownHostException, MalformedURLException... Is there other Exception that is very likely to occur?
Re: Which of the subclasses of IOException are more probably to be thrown?
The only one's I expect would be those thrown by the classes and methods used. Those would be listed in the API doc.