ZeroDivide.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Jul 2019 20:55:17 +0200
changeset 24417 03b083548da2
parent 24170 09200595d6d6
permissions -rw-r--r--
#REFACTORING by exept class: Smalltalk class changed: #recursiveInstallAutoloadedClassesFrom:rememberIn:maxLevels:noAutoload:packageTop:showSplashInLevels: Transcript showCR:(... bindWith:...) -> Transcript showCR:... with:...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24170
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
     1
"{ Encoding: utf8 }"
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
     2
7585
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
     3
"
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
     4
 COPYRIGHT (c) 2001 by eXept Software AG
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
     5
              All Rights Reserved
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
     6
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
     7
 This software is furnished under a license and may be used
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
     8
 only in accordance with the terms of that license and with the
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
    10
 be provided or otherwise made available to, or used by, any
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
    11
 other person.  No title to or ownership of the software is
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
    12
 hereby transferred.
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
    13
"
5947
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
"{ Package: 'stx:libbasic' }"
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
20458
55727803f73d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 14717
diff changeset
    16
"{ NameSpace: Smalltalk }"
55727803f73d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 14717
diff changeset
    17
5947
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
DomainError subclass:#ZeroDivide
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	instanceVariableNames:''
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	classVariableNames:''
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	poolDictionaries:''
6218
f528bf2bcc5f category
Claus Gittinger <cg@exept.de>
parents: 5969
diff changeset
    22
	category:'Kernel-Exceptions-Errors'
5947
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
6218
f528bf2bcc5f category
Claus Gittinger <cg@exept.de>
parents: 5969
diff changeset
    25
!ZeroDivide class methodsFor:'documentation'!
f528bf2bcc5f category
Claus Gittinger <cg@exept.de>
parents: 5969
diff changeset
    26
7585
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
    27
copyright
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
    28
"
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
    29
 COPYRIGHT (c) 2001 by eXept Software AG
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
    30
              All Rights Reserved
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
    31
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
    32
 This software is furnished under a license and may be used
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
    33
 only in accordance with the terms of that license and with the
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
    35
 be provided or otherwise made available to, or used by, any
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
    36
 other person.  No title to or ownership of the software is
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
    37
 hereby transferred.
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
    38
"
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
    39
!
87d76b40f897 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7584
diff changeset
    40
6218
f528bf2bcc5f category
Claus Gittinger <cg@exept.de>
parents: 5969
diff changeset
    41
documentation
f528bf2bcc5f category
Claus Gittinger <cg@exept.de>
parents: 5969
diff changeset
    42
"
f528bf2bcc5f category
Claus Gittinger <cg@exept.de>
parents: 5969
diff changeset
    43
    Raised when a division by zero is attempted.
21863
fca2a068f458 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20458
diff changeset
    44
fca2a068f458 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20458
diff changeset
    45
    To get the (in our oppinion: invalid) behavior of some programming languages such as JavaSript,
fca2a068f458 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20458
diff changeset
    46
    which do not report division by zero exceptions,
fca2a068f458 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20458
diff changeset
    47
    use the following code:
fca2a068f458 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20458
diff changeset
    48
    
fca2a068f458 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20458
diff changeset
    49
        ZeroDivide ignoreIn:[ x / 0.0 ] 
fca2a068f458 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20458
diff changeset
    50
fca2a068f458 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20458
diff changeset
    51
    i.e.    
fca2a068f458 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20458
diff changeset
    52
        ZeroDivide ignoreIn:[ 1.0 / 0.0 ] 
fca2a068f458 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20458
diff changeset
    53
    returns +Inf,   
fca2a068f458 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20458
diff changeset
    54
    and
fca2a068f458 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20458
diff changeset
    55
        ZeroDivide ignoreIn:[ -1.0 / 0.0 ] 
fca2a068f458 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20458
diff changeset
    56
    returns -Inf instead.    
6218
f528bf2bcc5f category
Claus Gittinger <cg@exept.de>
parents: 5969
diff changeset
    57
"
7584
2104df18c2af example
Claus Gittinger <cg@exept.de>
parents: 6690
diff changeset
    58
!
2104df18c2af example
Claus Gittinger <cg@exept.de>
parents: 6690
diff changeset
    59
2104df18c2af example
Claus Gittinger <cg@exept.de>
parents: 6690
diff changeset
    60
examples
2104df18c2af example
Claus Gittinger <cg@exept.de>
parents: 6690
diff changeset
    61
"
2104df18c2af example
Claus Gittinger <cg@exept.de>
parents: 6690
diff changeset
    62
    the following leads into a debugger:
2104df18c2af example
Claus Gittinger <cg@exept.de>
parents: 6690
diff changeset
    63
                                                                    [exBegin]
2104df18c2af example
Claus Gittinger <cg@exept.de>
parents: 6690
diff changeset
    64
        |divisor|
2104df18c2af example
Claus Gittinger <cg@exept.de>
parents: 6690
diff changeset
    65
2104df18c2af example
Claus Gittinger <cg@exept.de>
parents: 6690
diff changeset
    66
        divisor := 0.
2104df18c2af example
Claus Gittinger <cg@exept.de>
parents: 6690
diff changeset
    67
        Transcript showCR: ( 5 / divisor ).
2104df18c2af example
Claus Gittinger <cg@exept.de>
parents: 6690
diff changeset
    68
                                                                    [exEnd]
2104df18c2af example
Claus Gittinger <cg@exept.de>
parents: 6690
diff changeset
    69
2104df18c2af example
Claus Gittinger <cg@exept.de>
parents: 6690
diff changeset
    70
10273
84eddf61acc5 Fix spelling in example comment
Stefan Vogel <sv@exept.de>
parents: 7585
diff changeset
    71
    the following does NOT lead into a debugger:
7584
2104df18c2af example
Claus Gittinger <cg@exept.de>
parents: 6690
diff changeset
    72
                                                                    [exBegin]
2104df18c2af example
Claus Gittinger <cg@exept.de>
parents: 6690
diff changeset
    73
        |divisor|
2104df18c2af example
Claus Gittinger <cg@exept.de>
parents: 6690
diff changeset
    74
2104df18c2af example
Claus Gittinger <cg@exept.de>
parents: 6690
diff changeset
    75
        divisor := 0.
2104df18c2af example
Claus Gittinger <cg@exept.de>
parents: 6690
diff changeset
    76
        [
2104df18c2af example
Claus Gittinger <cg@exept.de>
parents: 6690
diff changeset
    77
            Transcript showCR: ( 5 / divisor ).
10273
84eddf61acc5 Fix spelling in example comment
Stefan Vogel <sv@exept.de>
parents: 7585
diff changeset
    78
        ] on:ZeroDivide do:[
84eddf61acc5 Fix spelling in example comment
Stefan Vogel <sv@exept.de>
parents: 7585
diff changeset
    79
            Transcript flash.
84eddf61acc5 Fix spelling in example comment
Stefan Vogel <sv@exept.de>
parents: 7585
diff changeset
    80
        ]
7584
2104df18c2af example
Claus Gittinger <cg@exept.de>
parents: 6690
diff changeset
    81
                                                                    [exEnd]
21867
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
    82
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
    83
    the following suppresses the exception and results in NaN/Inf:
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
    84
                                                                    [exBegin]
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
    85
        |divisor|
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
    86
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
    87
        divisor := 0.
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
    88
        Transcript showCR: (ZeroDivide ignoreIn:[ 5 / divisor ])
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
    89
                                                                    [exEnd]
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
    90
                                                                    [exBegin]
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
    91
        |divisor|
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
    92
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
    93
        divisor := 0.
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
    94
        Transcript showCR: (ZeroDivide ignoreIn:[ -5 / divisor ])
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
    95
                                                                    [exEnd]
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
    96
                                                                    [exBegin]
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
    97
        |divisor|
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
    98
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
    99
        divisor := 0.
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
   100
        Transcript showCR: (ZeroDivide ignoreIn:[ 0 / divisor ])
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
   101
                                                                    [exEnd]
7584
2104df18c2af example
Claus Gittinger <cg@exept.de>
parents: 6690
diff changeset
   102
"
6218
f528bf2bcc5f category
Claus Gittinger <cg@exept.de>
parents: 5969
diff changeset
   103
! !
5947
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
6690
07ef28245da8 notifier now initialized here
Claus Gittinger <cg@exept.de>
parents: 6218
diff changeset
   105
!ZeroDivide class methodsFor:'initialization'!
07ef28245da8 notifier now initialized here
Claus Gittinger <cg@exept.de>
parents: 6218
diff changeset
   106
07ef28245da8 notifier now initialized here
Claus Gittinger <cg@exept.de>
parents: 6218
diff changeset
   107
initialize
07ef28245da8 notifier now initialized here
Claus Gittinger <cg@exept.de>
parents: 6218
diff changeset
   108
    NotifierString := 'division by zero'.
07ef28245da8 notifier now initialized here
Claus Gittinger <cg@exept.de>
parents: 6218
diff changeset
   109
! !
07ef28245da8 notifier now initialized here
Claus Gittinger <cg@exept.de>
parents: 6218
diff changeset
   110
24170
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   111
!ZeroDivide class methodsFor:'instance creation'!
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   112
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   113
dividend:aNumber
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   114
    ^ self new originator:aNumber
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   115
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   116
    "
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   117
     [
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   118
         (ZeroDivide dividend:10) raise
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   119
     ] on:ZeroDivide do:[:ex |
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   120
         self assert:ex dividend == 10
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   121
     ].    
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   122
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   123
     [
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   124
         10 / 0
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   125
     ] on:ZeroDivide do:[:ex |
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   126
         self assert:ex dividend == 10
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   127
     ].    
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   128
    "
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   129
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   130
    "Created: / 27-05-2019 / 14:45:29 / Claus Gittinger"
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   131
! !
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   132
5947
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
!ZeroDivide methodsFor:'accessing'!
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
14717
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   135
defaultResumeValue
21863
fca2a068f458 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20458
diff changeset
   136
    "return +/- infinity here, if ever proceeded"
14717
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   137
21863
fca2a068f458 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20458
diff changeset
   138
    |poorReceiver|
fca2a068f458 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20458
diff changeset
   139
    
21867
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
   140
    poorReceiver := self dividend.
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
   141
    poorReceiver isZero ifTrue:[
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
   142
        ^ poorReceiver class NaN
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
   143
    ].    
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
   144
    poorReceiver negative ifTrue:[
21863
fca2a068f458 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20458
diff changeset
   145
        ^ poorReceiver class negativeInfinity
fca2a068f458 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20458
diff changeset
   146
    ].    
fca2a068f458 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20458
diff changeset
   147
    ^ poorReceiver class infinity
14717
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   148
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   149
    "
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   150
     |a b|
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   151
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   152
     a := 5.
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   153
     b := 0.
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   154
     ZeroDivide handle:[:ex |
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   155
        Transcript showCR:('division by zero - dividend was: ' , ex dividend printString).
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   156
        ex proceed
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   157
     ] do:[
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   158
        a / b
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   159
     ]            
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   160
    "
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   161
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   162
    "
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   163
     |a b|
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   164
21863
fca2a068f458 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20458
diff changeset
   165
     a := -5.0.
14717
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   166
     b := 0.0.
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   167
     ZeroDivide handle:[:ex |
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   168
        Transcript showCR:('division by zero - dividend was: ' , ex dividend printString).
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   169
        ex proceed
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   170
     ] do:[
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   171
        a / b
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   172
     ]            
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   173
    "
21863
fca2a068f458 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20458
diff changeset
   174
21867
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
   175
    "Modified: / 20-06-2017 / 17:55:40 / cg"
14717
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   176
!
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   177
5947
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
dividend
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
    "Return the number that was being divided by zero."
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
24170
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   181
    ^ originator
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   182
"/    ^ parameter receiver
5947
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
    "
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
     |a b|
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
     a := 5.
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
     b := 0.
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
     Integer divisionByZeroSignal handle:[:ex |
5969
ed98cd153ecc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5947
diff changeset
   190
        Transcript showCR:('division by zero - dividend was: ' , ex dividend printString)
5947
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
     ] do:[
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
        a // b
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
     ]
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
    "
24170
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   195
09200595d6d6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21867
diff changeset
   196
    "Modified: / 27-05-2019 / 14:49:41 / Claus Gittinger"
5947
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
! !
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
!ZeroDivide class methodsFor:'documentation'!
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
version
20458
55727803f73d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 14717
diff changeset
   202
    ^ '$Header$'
21867
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
   203
!
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
   204
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
   205
version_CVS
35e2dfcb1e46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21863
diff changeset
   206
    ^ '$Header$'
5947
45351eedb5a1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
! !
7584
2104df18c2af example
Claus Gittinger <cg@exept.de>
parents: 6690
diff changeset
   208
14717
8bd5b56dd171 class: ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 10273
diff changeset
   209
6690
07ef28245da8 notifier now initialized here
Claus Gittinger <cg@exept.de>
parents: 6218
diff changeset
   210
ZeroDivide initialize!