public class HelloWorld {
public static void main(String args[]) {
try {
A a = new A();
a.sayHi("java.io.PrintStream");
} catch (Exception e) {
System.out.println(e);
} finally {
System.out.println("done");
}
}
}
class A {
public void sayHi(String className) throws ClassNotFoundException {
Class.forName(className);
}
}
public class HelloWorld {
public static void main(String args[]) throws Exception {
try {
A a = new A();
a.sayHi("");
} catch (Exception e) {
System.out.println(e);
throw e;
} finally {
System.out.println("done");
}
}
}
class A {
public void sayHi(String className) throws ClassNotFoundException {
Class.forName(className);
}
}
public class HelloWorld {
public static void main(String args[]) {
try {
throwCE();
} catch (CE ce) {
System.out.println(ce.getMessage());
ce.printStackTrace();
} finally {
System.out.println("done");
}
}
public static void throwCE() throws CE {
throw new CE();
}
}
class CE extends Throwable {
private static final long serialVersionUID = 1L;
@Override
public void printStackTrace() {
System.out.println("CE Stack Trace");
}
@Override
public String getMessage() {
return "CE Message";
}
}
下列哪种方法不是 Throwable 类的构造方法__。
A. Throwable()
B. Throwable(String message)
C. Throwable(Throwable cause, String message)
D. Throwable(Throwable cause)
下列异常类中不是继承自RuntimeException类的是__。
A. ArithmticException
B. NullPointerException
C. IndexOutOfBoundException
D. FileNotFoundException
下列不是用来捕获处理异常的关键字是__。
A. throws
B. try
C. catch
D. finally
下列关键字哪个是用来在方法名后声明抛出异常的__。
A. throw
B. throws
C. enum
D. final
在抛出异常时, 会自动调用这个异常的是哪个方法__。
A. clone()
B. getMessage()
C. fillInStackTrace()
D. toString()
编写一个自定义异常类,要求继承 Execption 类,在 main 方法中抛出这个异常并进行捕获处理。