public class TestThrows {
public static void main(String[] args) {
try {//监听异常
new TestThrows().sayHello("aa");
System.out.println("hello");
} catch (Exception e) {//捕获异常
System.out.println(e);//只输出是什么异常
e.printStackTrace();//输出异常的相关信息
}
}
private void sayHello(String string) throws Exception {
throw new Exception("出问题啦");//抛出异常的地方
}
}