Skip to content

Commit

Permalink
Fail when reading uninitialized variables
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegSmelov committed Mar 3, 2018
1 parent 87042cb commit 0eabe0f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/omgrofl/interpreter/Variable.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package omgrofl.interpreter;

import omgrofl.interpreter.exceptions.ScriptRuntimeException;

public class Variable {

protected Memory memory;
Expand All @@ -11,7 +13,12 @@ public Variable(Memory memory, String name) {
}

public Object getValue() {
return memory.getVariable(name.toLowerCase());
Object value = memory.getVariable(name.toLowerCase());
if (value == null) {
throw new ScriptRuntimeException(
"Attempt to read uninitialized variable " + name);
}
return value;
}

public String getName() {
Expand Down

0 comments on commit 0eabe0f

Please sign in to comment.