在Objective-C中返回后,代码终于得到运行吗? [英] Does code in finally get run after a return in Objective-C?

查看:99
本文介绍了在Objective-C中返回后,代码终于得到运行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下代码:

@try {
  if (something.notvalid)
  {
    return;
  }
  // do something else
} @catch (NSException *ex) {
  // handle exception
} @finally {
  NSLog(@"finally!");
}

如果某事无效,我从试用中返回,代码是否执行 @finally ?我相信这应该是别人所说的,不要这么认为,我目前无法测试。

If something is not valid and I return from within the try, does the code in @finally execute or not? I believe that it should but others I've spoken to don't think so and I'm unable to test this at the moment.

推荐答案

@finally代码总是根据此处此处

@finally code always executes according to here and here.


一个@finally块包含代码,
必须执行,无论是否抛出

A @finally block contains code that must be executed whether an exception is thrown or not.

这篇关于在Objective-C中返回后,代码终于得到运行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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