如何调用 一个类后面有throws IOException

2024-12-24 23:01:47
推荐回答(1个)
回答1:

给你示例一个:
public class T {
public static void a() throws IOException {
// to do something;
}

public static void main(String[] args) {
try{
T.a();// bacause this method may throw IOException
// so you can try - catch this IOException or
// throw IOException after main method as this
// ...main(String[] args) throws IOException {}
}catch (IOException e) {
// you can do something when you catch this IOException ;
e.printStackTrace();
}
}
}
// 当你调用的方法抛出一个异常,要么在方法体中捕捉这个异常或者是直接抛出这个异常,