如何抛出 IOException? [英] how to throw an 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?
}
}
嗨!我刚开始学习异常,需要抓住一个expetion,所以请谁能给我一个解决方案?我会很感激.谢谢!
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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文