try,catch和finally中的执行顺序是什么 [英] What is the order of execution in try,catch and finally

查看:206
本文介绍了try,catch和finally中的执行顺序是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我们在尝试中给出这样的return语句,执行顺序将是

  try {
--- ----
-----
返回a;
}

渔获{
}
最终{
}

如果尝试返回,这里的执行顺序是什么。请让我知道

解决方案

http://docs.oracle.com/javase/tutorial/essential/exceptions/finally.html



http:// docs .oracle.com / javase / specs / jls / se7 / html / jls-14.html#jls-14.20.2



最终始终执行。如果在尝试中有返回,则其余的 try catch 不执行,然后最终执行(从最里面到最外面),然后函数退出。 / p>

If we give return statement like this in try, what will be the order of execution

try{
--- ----
-----
return a;
}

catch{
}
finally{
}

Here what will be order of execution if there is return in try. Please let me know

解决方案

http://docs.oracle.com/javase/tutorial/essential/exceptions/finally.html

http://docs.oracle.com/javase/specs/jls/se7/html/jls-14.html#jls-14.20.2

finally always executes. If there is a return in try, the rest of try and catch don't execute, then finally executes (from innermost to outermost), then the function exits.

这篇关于try,catch和finally中的执行顺序是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆