'From Squeak3.1alpha [latest update: #''Squeak3.1alpha'' of 20 February 2001 update 3892] on 10 April 2001 at 1:08:42 pm'! "Change Set: IfErrorEnhancement-mdr Date: 10 April 2001 Author: Mike Rutenberg Enhances ifError: to also allow error blocks which contain no arguments. This change adds support for a form of usage which is already in the system :-) and makes it a bit easier to read and write simple error handling code. [-1 sqrt] ifError: [:err :rcvr | 9 ]. (old form) [-1 sqrt] ifError: [ 9 ]. (new additional form) Also corrects two minor ifError: uses which were incorrect. "! !AbstractLauncher methodsFor: 'private' stamp: 'mdr 4/10/2001 10:50'! numericParameterAtOneOf: alternateParameterNames ifAbsent: aBlock "Return the parameter named using one of the alternate names or an empty string" | parameterValue | parameterValue _ self parameterAtOneOf: alternateParameterNames. parameterValue isEmpty ifTrue: [^aBlock value]. ^[Number readFrom: parameterValue] ifError: aBlock ! ! !BlockContext methodsFor: 'accessing' stamp: 'mdr 4/10/2001 10:34'! numArgs "Answer the number of arguments that must be used to evaluate this block" ^nargs! ! !BlockContext methodsFor: 'evaluating' stamp: 'mdr 4/10/2001 13:08'! ifError: errorHandlerBlock "Evaluate the block represented by the receiver, and normally return it's value. If an error occurs, the errorHandlerBlock is evaluated, and it's value is instead returned. The errorHandlerBlock must accept either no parameters, or two (the error message and the receiver). The receiver should not contain an explicit return statement as this would leave an obsolete error handler hanging around." "Examples: [1 whatsUpDoc] ifError: [:err :rcvr | 'huh?']. [1 / 0] ifError: [:err :rcvr | 'ZeroDivide' = err ifTrue: [Float infinity] ifFalse: [self error: err]] " | lastHandler val activeProcess errBlockArgs | errBlockArgs _ errorHandlerBlock numArgs. (errBlockArgs = 2) | (errBlockArgs = 0) ifFalse: [self error: 'error block must accept zero or two arguments (err rcvr)']. activeProcess _ Processor activeProcess. lastHandler _ activeProcess errorHandler. activeProcess errorHandler: [:aString :aReceiver | activeProcess errorHandler: lastHandler. (errBlockArgs = 2) ifTrue: [^ errorHandlerBlock value: aString value: aReceiver ] ifFalse: [^ errorHandlerBlock value ]]. val _ self on: Error do: [:ex | activeProcess errorHandler: lastHandler. (errBlockArgs = 2) ifTrue: [^ errorHandlerBlock value: ex description value: ex receiver ] ifFalse: [^ errorHandlerBlock value ]]. activeProcess errorHandler: lastHandler. ^ val ! ! !IRCMorph methodsFor: 'interface' stamp: 'mdr 4/10/2001 10:52'! sendCommand: aString | message | message _ [IRCProtocolMessage fromString: aString asString] ifError: [nil]. message ifNil: [^ false]. connection sendMessage: message. ^ true ! !