From 56f4704c1292e4941d27a9971f5652a27e755672 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Wed, 12 Apr 2017 12:44:59 +0200 Subject: Catch undefined division, modulo operations --- repl.d | 12 ++++++++++-- 1 file 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; -- cgit v1.2.3