aboutsummaryrefslogtreecommitdiff
path: root/repl.d
diff options
context:
space:
mode:
Diffstat (limited to 'repl.d')
-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;