我试图捕获 FileNotFound 异常,以便我的程序在抛出异常时打印一条消息,而不是打印异常。这是我的代码:
import java.io.IOException;
import java.util.Scanner;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class SeegeeSOGFinder10
{
public static void main(String args[]) throws InterruptedException, IOException
{
// Some code here
int i = 0;
if(choice.equalsIgnoreCase("blah"))
{
try
{
while(i < j)
{
// Loop code
i++;
}
}
catch(java.net.SocketTimeoutException e) // This is where I am having trouble, These 2 exceptions are still thrown and are printed and my message is not shown
{
System.out.println("Recieved HTTP timeout. Maybe we got rate limited? Slepping for 30 seconds.");
Thread.sleep(30000);
}
catch(java.io.FileNotFoundException e)
{
System.out.println("File Not Found!");
}
System.out.println("Done!");
}
else
{
System.out.println("Invalid Choice");
}
}
// Some more code
}
代码在我遇到问题的地方被注释了,这两个错误仍然被抛出,并且我的消息没有被打印出来。我尝试将 try catch 块包含在循环内,甚至将整个程序放在 try catch 块中,结果相同。