diff --git a/src/com/craftinginterpreters/lox/Interpreter.java b/src/com/craftinginterpreters/lox/Interpreter.java index 57e697c..1d87b87 100644 --- a/src/com/craftinginterpreters/lox/Interpreter.java +++ b/src/com/craftinginterpreters/lox/Interpreter.java @@ -119,9 +119,14 @@ class Interpreter implements Expr.Visitor { } throw new RuntimeError(expr.operator, "Operands must be two numbers or two strings."); - case SLASH: + case SLASH: { checkNumberOperands(expr.operator, left, right); - return (double) left / (double) right; + double rhs = (double) right; + if (rhs == 0) { + throw new RuntimeError(expr.operator, "Division by zero."); + } + return (double) left / rhs; + } case STAR: checkNumberOperands(expr.operator, left, right); return (double) left * (double) right;