'From Squeakland.396-Nihongo7.29 of 14 March 2005 [latest update: #34] on 15 March 2005 at 11:46 am'! "Change Set: divZeroRevised Date: 14 March 2005 Author: Yoshiki Ohshima Attempt to handle divZero with #//, #\\ gracefully."! !PhraseTileMorph methodsFor: 'mouse' stamp: 'tak 3/15/2005 11:40'! catchDivideByZero: aStream indent: tabCount "See if I am have divide as my operator. If so, insert a test in the argument to divide." | exp | submorphs second type = #operator ifFalse: [^false]. "not me" exp _ submorphs second operatorOrExpression. (#(/ // \\) includes: exp) ifFalse: [^false]. "not me" aStream space. aStream nextPutAll: '(self beNotZero: '. (submorphs third) storeCodeOn: aStream indent: tabCount. aStream nextPut: $). ^true! ! !Player methodsFor: 'misc' stamp: 'yo 3/14/2005 13:22'! beNotZero: aNumber "This is a runtime check if the arg to divide in a script is zero. If it is, put up a message from M. Mouse. Return 0.001 instead of 0. Note the time. If fails again within 1 min., don't tell the user again." aNumber = 0 ifFalse: [^ aNumber]. "normal case" "We have a problem" TimeOfError ifNil: [TimeOfError _ Time totalSeconds] ifNotNil: [(Time totalSeconds - TimeOfError) > 45 ifTrue: [ TimeOfError _ Time totalSeconds. "in case user interrupt and reenter" PopUpMenu inform: 'Dividing by zero makes a number too large for even a Sorcerer to handle. Please change your script. -- M. Mouse' translated. TimeOfError _ Time totalSeconds]]. ^ 0.001! !