try中含有throw到底是怎么回事,应该怎么理解?
public class excTest {
public static void main(String[] args) {
try{
System.out.println("try中含有throw");
throw new e1();
}
catch(e1 e){
System.out.println("fsasd");
System.out.println(e.getMessage());
}
}
}
public class e1 extends Exception{
public e1(){
super("dafsf");
}
}如上,上面这个控制台显示:
try中含有throw
fsasd
dafsf
这个throw应该怎么理解?
不是把异常抛到main方法吗?按这里的逻辑应该是在catch块中输出啊!