12.1 答:将检测错误于处理错误分开来了
答:12.2 System.out.println(1/0);
答:12.3 long.MAX_VALUE 加 1 会导致溢出 不会抛异常
第十二章
答:12.4 .当发生异常时,Java 在 catch 子句中搜索处理程序。因此,要在程序中捕获异
常,需要编写一个 try-catch 语句,如下所示:
尝试{
}
catch(Exception ex){
}
答:12.5 value is too small
Continue after the catch block
更换后:Continue after the catch block
答:12.6 a: 0+1
答:12.7: Throwable 是所有异常类的跟。所有的 Java 异常类都直接或者间接地继承它。
答:12.8:RuntimeException
NulllPointerException
b: 0
StringIndexOutOfBoundsException
NulllPointerException
Infinity
classCastException
答:12.9 因为任何代码都可能发生系统错误和运行错误,在方法后面声明
Public void myMthod() throws Exception 可以声明多异常
答:12.10 必检异常就是编译器强制程序猿检查并通过 try——catch 来处的异常
RuntimeException and Error 以及他们的之类可以不用程序猿来声明处理
答:12.11 使用 throw 不能
答:12.12 throw 作用是抛出异常 throws 作用是声明异常
答:12.13 会执行 statement3 会 会
答:12.14 抛出 ArrayIndexOutOfBoundsException,
答:12.15 ArithmeticException。
答:12.16 StringIndexOutOfBoundsException
答:12.17 返回异常的描述
答:12.18 将信息跟踪到控制台
答:12.19 不会
答:12.20 public void m(int value ) throws Exception{
if(value<40)
Throw new Exception (“the value is too small”);
}
答:12.21 会执行 statement4 会
会 会
会 不会
答:12.22 它是正确的 但是最好是使用正则表达式来筛选
答:12.23 会 会
会 会
会 不会、
会 不会
答:12.24 ava.lang.Exception:method1 的新信息
at ChainedExceptionDemo.method1(ChainedExceptionDemo.java:16)
在 ChainedExceptionDemo.main(ChainedExceptionDemo.java:4)
答:12.25 继承 Exception 或者 Exception 的子类
答:12.26 RadiusException
答:12.27 \必须用\\转义
答:12.28 File.exists(file)
File.delete(file)
File.renameTo(File)
File.listFile(File)
答:12.29 不可以 不可以.File 类可用于获取文件属性和操作文件,但不能执行 I / O.
答:12.30 要为文件创建 PrintWriter,请使用新的 PrintWriter(文件名)。
答:12.31 amount is 32.320000 3.232000e + 01
amount is 32.3200 3.2320e + 01
False
答:12.32
public static void main(String [] args)throws Exception {
Java
try(java.io.PrintWriter output = new
java.io.PrintWriter(“temp.txt”);){
output.printf(“金额是%f%e
“,32.32,32.32);
output.printf(“金额为%5.4f%5.4e
“,32.32,32.32);
output.printf(“%6B
“,(1> 2));
output.printf(“%6S
“,”Java“);
}
}
}
答:12.33 Scanner input=new Scanner (File);
因为文件使用中有可能报错
程序正常运行,但是最好不要这么做
答:12.34 不是 \
答:12.35
Scanner= new Scanner (System.in);
int intValue = input.nextInt();
double doubleValue = input.nextDouble();
String line = input.nextLine();
答:12.36 intValue 包含 45. doubleValue 包含 57.8,而行包含'','7','8','9'。
12.37 答:45 57.5 789
12.38 答: Scanner input =new Scanner(urL.openStream());
12.39 答:1istOfPendingURLs 遍历 可能有重复;