8

我有以下代码块,它使用在http://www.jcraft.com/jsch/找到的 JSCH 库

try {
    channel.put(f, filename);
} catch (FileNotFoundException e) {
    System.out.println("no file.");
}

我知道当 f 指定的文件在本地找不到时 put 方法可以抛出 FileNotFoundException,但是 eclipse 告诉我 catch 块不可访问,并且永远不会抛出该异常。当我更改为:

try {
    channel.put(f, filename);
} catch (Exception e) {
    System.out.println(e.getMessage());
}

我得到:

java.io.FileNotFoundException: C:\yo\hello2 (The system cannot find the file specified)

有任何想法吗?

4

2 回答 2

8

我认为你FileNotFoundException被包裹在另一个被该channel方法抛出的东西中,因此你无法抓住它。

尝试打印该方法抛出的异常的类:

...
} catch (Exception e) {
   System.out.println(e.getClass());
}
于 2011-09-06T16:24:54.460 回答
2

检查您的导入语句以确保您没有FileNotFoundException从包中导入一个类java.io

于 2011-09-06T16:13:44.327 回答