|
Block Specification SheetPortable Object Compiler (c) 1997,98,2000. All Rights Reserved.
BlockInherits from: ObjectMaturity Index: Experimental
Class DescriptionObjective-C Blocks are similar to block expressions in Smalltalk. Blocks are a way to express deferred computations; computations to be written at one place but invoked from another.The Portable Object Compiler uses blocks for error handling i.e., the processing of exceptional conditions that interrupt the normal flow of program execution, such as out of memory, division by zero etc. The Object method error: and the Block instance method ifError: are used for this. Blocks are a non-standard part of the Objective-C language; this implementation, the first and most powerful as far as we know, is based on Brad Cox's TaskMaster paper where the same concept is discussed under the name of Action Expressions. For a discussion on what Blocks are, and how to use them, we refer to the document Objective-C Blocks. The compiler has an option -noBlocks that can be used to turn off the special syntax for Blocks.
Method typesException HandlingEvaluating BlocksControl FlowMethodserrorHandler+errorHandlerReturns the default handler, as set by errorHandler:, or, if none was explicitely set, it uses the following handler:
id errorHandler = { :msg :rcv | fprintf(stderr,[msg str]);abort(); }; errorHandler:+errorHandler:aHandlerMake aHandler the default error handler. Returns the handler that was previously registered as default handler.
ifError:-ifError:aHandlerEvaluates the receiver of the message and returns its return value. If an exception is raised, evaluates aHandler. This works by pushing aHandler on a stack of error handlers, the method halt: temporarily pops off an error handler and evaluates it with a message and receiver object as arguments :
Note: It is an error to have a non-local return from within the receiver, as this would leave an error handler dangling. It is allowed to return however, from within the error handler.[ { ... } ifError: { :msg :rcv | ... }];
value:ifError:-value:anObjectifError:aHandlerLike ifError: but the receiving block can take an argument.
value-valueEvaluates the receiver of the message and returns its return value.
intvalue- (int)intvalueEvaluates the receiver of the message and returns its return value.
atExit-atExitEvaluates the receiver of the message when the process exits. See the ANSI C function atexit() for more details. There's a maximum of 32 exit Blocks that can be registered to be automatically called on exit. Blocks are evaluated in reverse order of their registration.
value:-value:anObjectEvaluates, with anObject as argument, the receiver of the message and returns its return value.
intvalue:- (int)intvalue:anObjectEvaluates, with anObject as argument, the receiver of the message and returns its return value.
value:value:-value:firstObjectvalue:secondObjectEvaluates the receiver of the message with two arguments and returns its return value.
intvalue:value:- (int)intvalue:firstObjectvalue:secondObjectEvaluates the receiver of the message with two arguments and returns its return value.
repeatTimes:-repeatTimes:(int)nMethod to evaluate the receiver Block n times. Similar to the Smalltalk method timesRepeat: but with argument and receiver interchanged. Returns self.
|