eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'ZeroDivide':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: ZeroDivide


Inheritance:

   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

Description:


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.    


Class protocol:

initialization
o  initialize

instance creation
o  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
].


Instance protocol:

accessing
o  defaultResumeValue
return +/- infinity here, if ever proceeded

o  dividend
Return the number that was being divided by zero.


Examples:


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 ])


ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Mon, 21 Jun 2021 01:13:26 GMT