TryCatch jump to the catch

感情迁移 提交于 2020-01-17 19:23:34

问题


How can i jump to the catch block in a try catch :

try{

if(bla!=)
throws Exception();

}catch(exception){
//do
}

doesn't work ?


回答1:


bla!= should be followed by a condition, throws should be throw, Exception() should be new Exception(), exception should be Exception e

try {
 if (bla != null) // or anything else
  throw new Exception("Exception thrown");
} catch (Exception e) {
 System.out.println("Exception caught!");
 e.printStackTrace();
} 



回答2:


Look the Flow of a try-catch-finally Block



来源:https://stackoverflow.com/questions/22790114/trycatch-jump-to-the-catch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!