aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2017-04-12 12:44:59 +0200
committerAdrian Kummerlaender2017-04-12 12:44:59 +0200
commit56f4704c1292e4941d27a9971f5652a27e755672 (patch)
tree15e4da421d784cec8fcb71b02242cc3eeed478a2
parentc3aa90c4056f7e49197f7b240e39392776c913e6 (diff)
downloadslang-56f4704c1292e4941d27a9971f5652a27e755672.tar
slang-56f4704c1292e4941d27a9971f5652a27e755672.tar.gz
slang-56f4704c1292e4941d27a9971f5652a27e755672.tar.bz2
slang-56f4704c1292e4941d27a9971f5652a27e755672.tar.lz
slang-56f4704c1292e4941d27a9971f5652a27e755672.tar.xz
slang-56f4704c1292e4941d27a9971f5652a27e755672.tar.zst
slang-56f4704c1292e4941d27a9971f5652a27e755672.zip
Catch undefined division, modulo operations
-rw-r--r--repl.d12
1 files changed, 10 insertions, 2 deletions
diff --git a/repl.d b/repl.d
index 0ea192b..b70f8ac 100644
--- a/repl.d
+++ b/repl.d
@@ -88,13 +88,21 @@ void evaluate(string word) {
int b = stack.pop().get!int;
int a = stack.pop().get!int;
- stack.push(a / b);
+ if ( b == 0 ) {
+ throw new Exception("division by 0 undefined");
+ } else {
+ stack.push(a / b);
+ }
break;
case "%":
int b = stack.pop().get!int;
int a = stack.pop().get!int;
- stack.push(a % b);
+ if ( b == 0 ) {
+ throw new Exception("modulo 0 undefined");
+ } else {
+ stack.push(a % b);
+ }
break;
case ".":
stack.pop;