Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 异常错误,尽管尝试捕获并抛出异常尝试_Java_Exception_Try Catch_Throw - Fatal编程技术网

Java 异常错误,尽管尝试捕获并抛出异常尝试

Java 异常错误,尽管尝试捕获并抛出异常尝试,java,exception,try-catch,throw,Java,Exception,Try Catch,Throw,我非常困惑,因为我有下面的代码,我认为应该捕获异常: @SuppressWarnings(“未选中”) 公共静态字符串方法(String userToken,int-nthRecent)引发异常 { //我自己的用户令牌:35a5b026870c49f69d3c688779ff26db String tweet=tweets.get(最近); 尝试 { 字符串URL字符串=”https://api.dandelion.eu/datatxt/sent/v1/?lang=en&text="; ur

我非常困惑,因为我有下面的代码,我认为应该捕获异常:

@SuppressWarnings(“未选中”)
公共静态字符串方法(String userToken,int-nthRecent)引发异常
{
//我自己的用户令牌:35a5b026870c49f69d3c688779ff26db
String tweet=tweets.get(最近);
尝试
{
字符串URL字符串=”https://api.dandelion.eu/datatxt/sent/v1/?lang=en&text=";
urlString+=tweet;
urlString=urlString+“&token=“+userToken;
URL=新URL(URL字符串);
HttpURLConnection con=(HttpURLConnection)url.openConnection();
con.setRequestMethod(“GET”);
BufferedReader in=新的BufferedReader(新的InputStreamReader(con.getInputStream());
StringBuffer响应=新的StringBuffer();
弦线;
而((line=in.readLine())!=null)
{
响应。追加(行);
}
in.close();
返回response.toString();
con.disconnect();
}
捕获(例外e)
{
e、 printStackTrace();
返回null;
}

}
这是TwitterPart3的第42行?啊,第42行实际上是主方法
方法
被声明为抛出
异常
,它的调用者必须考虑到这一点。或者,只需删除
抛出异常
@singularity:从调用方方法
main
捕获它,或者将调用方方法声明为抛出异常。或者从
方法()
中删除
抛出异常
,因为它可能从未抛出异常。