Completion blocks
The syntax codeBlock whenExceptionDo: completionBlock runs the completion block if any exception occurs during the running of the code block. The completion block is not considered to have handled the exception. That is, a further exception handler is looked for after the completion block is run.
codeBlock whenExceptionDo: completionBlock
is equivalent to:
codeBlock
when: ExAll
do: [:signal |
completionBlock value.
signal resumeBlock: nil
signal signal].
The syntax codeBlock atEndOrWhenExceptionDo: completionBlock causes the completion block to be run whether an exception occurs during the running of the code block, or the code block successfully runs to completion. As above, the completion block is not considered to have handled the exception. That is, a further exception handler is looked for after the completion block is run.
codeBlock atEndOrWhenExceptionDo: completionBlock
is equivalent to:
| cleanedUp |
cleanedUp := false.
codeBlock
when: ExAll
do: [:signal |
completionBlock value.
cleanedUp := true.
signal resumable: false.
signal signal].
cleanedUp ifFalse: [completionBlock value]
Note that completion blocks are not passed any arguments.
Note:
After a completion block has been run because of an exception, the exception (actually the instance of Signal) is marked as being nonresumable before another handler is searched for. This prevents the completion block from being run multiple times.
Last modified date: 01/29/2015