62,614
社区成员
发帖
与我相关
我的任务
分享
import java.io.*;
/**
*
* @author supercodingman
* @version 1.0
*/
public class Test5 {
public void doException() throws IOException {
System.out.println("arithmeticExcption");
}
public static void main(String[] args) {
Test5 test = new Test5();
try {
test.doException();//所抛出的异常会返回给调用者处理
} catch (IOException e) {
e.printStackTrace();
}
}
}
package csdn.javase.excep.ex1;
import java.io.*;
/**
*
* @author supercodingman
* @version 2.0
*/
public class Test5 {
public void doException(){
try{
System.out.println("arithmeticExcption");
throw new IOException();
}catch(IOException ioe){
ioe.printStackTrace();
}
}
public static void main(String[] args) {
Test5 test = new Test5();
test.doException();//这样就不需在调用处捕获异常了
}
}
package test1;
import java.io.*;
public class Test5 {
public void doException() throws IOException {
System.out.println("arithmeticExcption");
}
public static void main(String[] args) {
Test5 test = new Test5();
try {
test.doException();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}