SixPing 2016-03-30 16:01 采纳率: 42.9%
浏览 2021

按书上写了一段代码java异常处理,不知道为什么不能运行,求大神指教

源代码如下:
package com.Sixping.Ncre;

import java.io.*;

public class ExceptionCatch {
public static void main(String[] args) {
try {
FileNotFoundException fis = new FileNotFoundException("text");
System.out.println("content of text is:");
} catch (FileNotFoundException e) {
System.out.println(e);
System.out.println("massage:" + e.getMessage());
e.printStackTrace(System.out);
} catch (IOException e) {
System.out.println(e);
}
}
}
运行显示如下:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Unreachable catch block for FileNotFoundException. This exception is never thrown from the try statement body
Unreachable catch block for IOException. This exception is never thrown from the try statement body

at com.Sixping.Ncre.ExceptionCatch.main(ExceptionCatch.java:10)

求大神指教。

  • 写回答

5条回答 默认 最新

  • threenewbee 2016-03-30 16:14
    关注

    说的很清楚
    This exception is never thrown from the try statement body
    这个异常在你的try语句体永远不会被丢出
    FileNotFoundException fis = new FileNotFoundException("text");
    throw fis; //加上

    评论

报告相同问题?

悬赏问题

  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形