这就是我现在所拥有的,这个方法打开了与http url的连接,
public static void setCameraList(String list) {
URL calculator;
try {
String url = "http://example.com/index.php?cameraList=" +URLEncoder.encode(list, "ISO-8859-1");
calculator = new URL(url);
URLConnection calcConnection = calculator.openConnection();
BufferedReader streamReader = new BufferedReader(new InputStreamReader(calcConnection.getInputStream()));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
}
这个工作很好,但有时当 url 无法访问或返回一些错误代码时,此方法
似乎会使整个应用程序崩溃。
我很好奇的是,为什么这个方法无法捕获Exception
?
另外,如果我添加这个:
catch(Throwable th){
}
这个方法
会捕获
与我在其中执行的操作相关的每个可能的错误/异常
吗?
最佳答案
我不是Java专家,但你应该考虑到异常和错误之间是有区别的。 你看了吗here ?
你可以发布堆栈跟踪吗? 谢谢
关于java - 在java中捕获异常以使应用程序继续执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15688926/