|
Class: ZeroDivide
Object
|
+--GenericException
|
+--Exception
|
+--Error
|
+--ProceedableError
|
+--ExecutionError
|
+--ArithmeticError
|
+--DomainError
|
+--ZeroDivide
- Package:
- stx:libbasic
- Category:
- Kernel-Exceptions-Errors
- Version:
- rev:
1.16
date: 2021/11/21 15:59:36
- 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.
copyrightCOPYRIGHT (c) 2001 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
accessing
-
defaultNotifierString
-
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.
Usage example(s):
|a b|
a := 5.
b := 0.
Integer divisionByZeroSignal handle:[:ex |
Transcript showCR:('division by zero - dividend was: ' , ex dividend printString)
] do:[
a // b
]
|
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 ])
|
|