Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Exceptions/Wren/exceptions.wren
Normal file
18
Task/Exceptions/Wren/exceptions.wren
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
var intDiv = Fn.new { |a, b|
|
||||
if (!(a is Num && a.isInteger) || !(b is Num && b.isInteger)) Fiber.abort("Invalid argument(s).")
|
||||
if (b == 0) Fiber.abort("Division by zero error.")
|
||||
if (a == 0) a = a.badMethod()
|
||||
return (a/b).truncate
|
||||
}
|
||||
|
||||
var a = [ [6, 2], [6, 0], [10, 5], [true, false], [0, 2] ]
|
||||
for (e in a) {
|
||||
var d
|
||||
var f = Fiber.new { d = intDiv.call(e[0], e[1]) }
|
||||
f.try()
|
||||
if (f.error) {
|
||||
System.print("Caught %(f.error)")
|
||||
} else {
|
||||
System.print("%(e[0]) / %(e[1]) = %(d)")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue