Detect division by zero: Difference between revisions

m
Line 2,036:
a/b
] on: ZeroDivide do:[:ex |
'you tried to divide %P by zero\n' printf:{ex suspendedContext receiver} on:Transcript.
didDivideByZero := true.
].
Line 2,042:
Transcript show:'bad bad bad, but I already told you in the handler'.
].</lang>
Note: works in all Smalltalks: printf is avalable in the public domain printfScanf package.
 
Alternative version, which gets any block as argument, evaluates it and returns true, if ZeroDivide happened (works in all Smalltalks):
Anonymous user