Confirmed users, Bureaucrats and Sysops emeriti
1,680
edits
No edit summary |
No edit summary |
||
| Line 19: | Line 19: | ||
When wrapping calls in a method, the first choice you'll have to make is whether to wrap specific calls or the whole method impl. Which one you pick is usually a matter of cleanliness. If there is a big method with a single Apple framework call in it, you might just want to wrap that specific call. Your choice of macros are these: | When wrapping calls in a method, the first choice you'll have to make is whether to wrap specific calls or the whole method impl. Which one you pick is usually a matter of cleanliness. If there is a big method with a single Apple framework call in it, you might just want to wrap that specific call. Your choice of macros are these: | ||
* <code>NS_OBJC_TRY_IGNORE</code> | * For wrapping calls that are not expressions, do not return values (we care about) | ||
* <code>NS_OBJC_TRY_ABORT</code> | ** <code>NS_OBJC_TRY_IGNORE</code> | ||
** <code>NS_OBJC_TRY_ABORT</code> | |||
An example of these in use: | |||
<code>NS_OBJC_TRY_ABORT([bar doSomething]);</code> | |||
<code> | * For wrapping expressions that return a value | ||
** <code>NS_OBJC_TRY_EXPR_NULL</code> | |||
** <code>NS_OBJC_TRY_EXPR_ABORT</code> | |||
An example of EXPR usage is: | |||
<code> | <code>foo = NS_OBJC_TRY_EXPR_ABORT([bar doSomething]);</code> | ||
The macros that include ABORT will kill the app if they catch an exception, you will almost always want to use these. It saves a lot of time if we don't have to think about recovery strategies for calls. In order to code for recovery you'd have to understand something about the context of the code you are working in. If we start seeing exceptions killing the app it'll be easy to go back and code the calls that are throwing for recovery. That probably won't happen and if it does it'll probably be just 1-2 calls we need to not abort on. | The macros that include ABORT will kill the app if they catch an exception, you will almost always want to use these. It saves a lot of time if we don't have to think about recovery strategies for calls. In order to code for recovery you'd have to understand something about the context of the code you are working in. If we start seeing exceptions killing the app it'll be easy to go back and code the calls that are throwing for recovery. That probably won't happen and if it does it'll probably be just 1-2 calls we need to not abort on. | ||