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.16 date: 2021/11/21 15:59:36
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.    

copyright

COPYRIGHT (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.

Class protocol:

accessing
o  defaultNotifierString

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.

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
     ]


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.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sun, 22 Dec 2024 04:17:15 GMT