【问题标题】:TryCatch jump to the catchTryCatch 跳转到 catch
【发布时间】:2014-05-12 11:26:29
【问题描述】:

如何在 try catch 中跳转到 catch 块:

try{

if(bla!=)
throws Exception();

}catch(exception){
//do
}

没有用?

【问题讨论】:

  • 定义doesn't work。你有编译时错误吗?你的代码不会抛出异常吗?或者也许异常是由不同的 catch 块处理的?
  • 你说的不起作用是什么意思?您的代码 sn-p 中有严重的语法错误。
  • 是的,你有 4 个语法错误,我想不到。

标签: java try-catch


【解决方案1】:

bla!= 后面应该跟一个条件,throws 应该是throwException() 应该是new Exception()exception 应该是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】:

    查看try-catch-finally 块的流程

    【讨论】:

      猜你喜欢
      • 2017-02-06
      • 2017-02-25
      • 1970-01-01
      • 1970-01-01
      • 2017-09-11
      • 2019-10-29
      • 2011-12-26
      • 2010-12-04
      • 1970-01-01
      相关资源
      最近更新 更多