Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,15 @@
|
|||
proc div_check {x y} {
|
||||
if {[catch {expr {$x/$y}} result] == 0} {
|
||||
puts "valid division: $x/$y=$result"
|
||||
} else {
|
||||
if {$result eq "divide by zero"} {
|
||||
puts "caught division by zero: $x/$y -> $result"
|
||||
} else {
|
||||
puts "caught another error: $x/$y -> $result"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach denom {1 0 foo} {
|
||||
div_check 42 $denom
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
proc div_check {x y} {
|
||||
try {
|
||||
puts "valid division: $x/$y=[expr {$x/$y}]"
|
||||
} trap {ARITH DIVZERO} msg {
|
||||
puts "caught division by zero: $x/$y -> $msg"
|
||||
} trap {ARITH DOMAIN} msg {
|
||||
puts "caught bad division: $x/$y -> $msg"
|
||||
} on error msg {
|
||||
puts "caught another error: $x/$y -> $msg"
|
||||
}
|
||||
}
|
||||
|
||||
foreach {num denom} {42 1 42 0 42.0 0.0 0 0 0.0 0.0 0 foo} {
|
||||
div_check $num $denom
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue