本文介绍了如何抛出IOException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
公共类ThrowException {public static void main(String [] args){
try {
foo();
}
catch(Exception e){
if(e instanceof IOException){
System.out.println(Completed!);
}
}
}
static void foo(){
//我应该在这里写什么来获取异常?
}
}
嗨!我刚刚开始学习例外情况,需要抓住机会,所以请任何人提供解决方案?
我非常感激。
谢谢!
解决方案
static void foo()throws IOException {
抛出新的IOException(你的消息);
}
public class ThrowException {
public static void main(String[] args) {
try {
foo();
}
catch(Exception e) {
if (e instanceof IOException) {
System.out.println("Completed!");
}
}
}
static void foo() {
// what should I write here to get an exception?
}
}
Hi! I just started learning exceptions and need to catch an expetion, so please can anybody provide me with a solution?I'd be very grateful.Thanks!
解决方案
static void foo() throws IOException {
throw new IOException("your message");
}
这篇关于如何抛出IOException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!