diff options
author | Adrian Kummerlaender | 2017-04-12 12:44:59 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2017-04-12 12:44:59 +0200 |
commit | 56f4704c1292e4941d27a9971f5652a27e755672 (patch) | |
tree | 15e4da421d784cec8fcb71b02242cc3eeed478a2 | |
parent | c3aa90c4056f7e49197f7b240e39392776c913e6 (diff) | |
download | slang-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.d | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -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; |