public class ExceptionExam {
public static void main(String[] args) {
int a;
int b;
double c;
a = 3;
b = 0;
c = a / b;
System.out.println(a + "/" + b + "=" + c);
}
}
public class ExceptionExam {
public static void main(String[] args) {
java.util.Date d = null;
System.out.println(d.getTime());
}
}
import java.io.*;
public class ExceptionExam {
public static void main(String[] args) {
FileInputStream fis = new FileInputStream("c:/test.txt");
}
}
public class TestException {
public TestException() {
}
public static void main(String[] args) {
String s = null;
try{
//可能会抛出特定异常的代码段
s.toString();
} catch(NullPointerException e) {
/*catch 从句中引入一个可能出现的异常,一个try块可以和多个catch块配合以处理多个异常当try块内的任何代码抛出了由catch 子句指定的异常,则try代码端中的程序将会终止执行,并跳到相应的catch代码块中来执行*/
s = "字符串";
System.out.println("Start........");
e.printStackTrace();
System.out.println("end..........");
} catch(Exception otherException) {
//如果otherException异常被抛出,执行这段代码
} finally{
/*无论是否出现异常,程序最后都会执行finally代码块中的内容*/
//当要把除内存之外的资源恢复到他们的初始状态就要用到finally语句
System.out.println("finally中的代码一般用于资源的回收");
}
}
}
















