|
Class: ZeroDivide
Object
|
+--GenericException
|
+--Exception
|
+--Error
|
+--ProceedableError
|
+--ExecutionError
|
+--ArithmeticError
|
+--DomainError
|
+--ZeroDivide
- Package:
- stx:libbasic
- Category:
- Kernel-Exceptions-Errors
- Version:
- rev:
1.12
date: 2019/05/27 12:51:49
- user: cg
- file: ZeroDivide.st directory: libbasic
- module: stx stc-classLibrary: libbasic
Raised when a division by zero is attempted.
To get the (in our oppinion: invalid) behavior of some programming languages such as JavaSript,
which do not report division by zero exceptions,
use the following code:
ZeroDivide ignoreIn:[ x / 0.0 ]
i.e.
ZeroDivide ignoreIn:[ 1.0 / 0.0 ]
returns +Inf,
and
ZeroDivide ignoreIn:[ -1.0 / 0.0 ]
returns -Inf instead.
initialization
-
initialize
-
instance creation
-
dividend: aNumber
-
[
(ZeroDivide dividend:10) raise
] on:ZeroDivide do:[:ex |
self assert:ex dividend == 10
].
[
10 / 0
] on:ZeroDivide do:[:ex |
self assert:ex dividend == 10
].
accessing
-
defaultResumeValue
-
return +/- infinity here, if ever proceeded
-
dividend
-
Return the number that was being divided by zero.
the following leads into a debugger:
|divisor|
divisor := 0.
Transcript showCR: ( 5 / divisor ).
|
the following does NOT lead into a debugger:
|divisor|
divisor := 0.
[
Transcript showCR: ( 5 / divisor ).
] on:ZeroDivide do:[
Transcript flash.
]
|
the following suppresses the exception and results in NaN/Inf:
|divisor|
divisor := 0.
Transcript showCR: (ZeroDivide ignoreIn:[ 5 / divisor ])
|
|divisor|
divisor := 0.
Transcript showCR: (ZeroDivide ignoreIn:[ -5 / divisor ])
|
|divisor|
divisor := 0.
Transcript showCR: (ZeroDivide ignoreIn:[ 0 / divisor ])
|
|