我有以下代码块,它使用位于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)
有任何想法吗?
我认为您FileNotFoundException
被该channel
方法包裹在另一个包中,因此您无法捕获它。
尝试打印方法抛出的异常的类:
...
} catch (Exception e) {
System.out.println(e.getClass());
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句