This commit is contained in:
gnembon committed 2021-03-09 14:43:29 -04:00
1 parent 72af3f732e
commit 29893ed28a
2 files changed
+12 -12

No files matched your search

@@ -16,7 +16,7 @@ public class ExpressionException extends RuntimeException implements ResolvedExc
public final Context context; public final Context context;
public final Tokenizer.Token token; public final Tokenizer.Token token;
public final List<FunctionValue> stack = new ArrayList<>(); public final List<FunctionValue> stack = new ArrayList<>();
private final Supplier<String> lazyStacktrace; private final Supplier<String> lazyMessage;
private String cachedMessage = null; private String cachedMessage = null;
public ExpressionException(Context c, Expression e, String message) public ExpressionException(Context c, Expression e, String message)
@@ -27,7 +27,7 @@ public class ExpressionException extends RuntimeException implements ResolvedExc
public ExpressionException(Context c, Expression e, Tokenizer.Token t, String message) public ExpressionException(Context c, Expression e, Tokenizer.Token t, String message)
{ {
super("Error"); super("Error");
lazyStacktrace = () -> makeMessage(c, e, t, message); lazyMessage = () -> makeMessage(c, e, t, message);
token = t; token = t;
context = c; context = c;
} }
@@ -35,7 +35,7 @@ public class ExpressionException extends RuntimeException implements ResolvedExc
{ {
super("Error"); super("Error");
this.stack.addAll(stack); this.stack.addAll(stack);
lazyStacktrace = () -> makeMessage(c, e, t, message); lazyMessage = () -> makeMessage(c, e, t, message);
token = t; token = t;
context = c; context = c;
} }
@@ -44,7 +44,7 @@ public class ExpressionException extends RuntimeException implements ResolvedExc
{ {
super("Error"); super("Error");
this.stack.addAll(stack); this.stack.addAll(stack);
lazyStacktrace = () -> makeMessage(c, e, t, messageSupplier.get()); lazyMessage = () -> makeMessage(c, e, t, messageSupplier.get());
token = t; token = t;
context = c; context = c;
} }
@@ -89,7 +89,7 @@ public class ExpressionException extends RuntimeException implements ResolvedExc
public String getMessage() { public String getMessage() {
if (cachedMessage == null) if (cachedMessage == null)
{ {
cachedMessage = lazyStacktrace.get(); cachedMessage = lazyMessage.get();
} }
return cachedMessage; return cachedMessage;
} }
@@ -8,8 +8,8 @@ import carpet.script.value.Value;
public class ThrowStatement extends InternalExpressionException public class ThrowStatement extends InternalExpressionException
{ {
private final Throwables thrownExceptionType; private final Throwables type;
private final Value exceptionData; private final Value data;
/** /**
* Creates a throw exception from a value, and assigns it a specified message. * Creates a throw exception from a value, and assigns it a specified message.
@@ -20,8 +20,8 @@ public class ThrowStatement extends InternalExpressionException
public ThrowStatement(Value data, Throwables type) public ThrowStatement(Value data, Throwables type)
{ {
super(type.getId()); super(type.getId());
exceptionData = data; this.data = data;
thrownExceptionType = type; this.type = type;
} }
/** /**
@@ -36,12 +36,12 @@ public class ThrowStatement extends InternalExpressionException
public ThrowStatement(String message, Throwables type) public ThrowStatement(String message, Throwables type)
{ {
super(type.getId()); super(type.getId());
this.exceptionData = StringValue.of(message); this.data = StringValue.of(message);
this.thrownExceptionType = type; this.type = type;
} }
@Override @Override
public ExpressionException promote(Context c, Expression e, Token token) { public ExpressionException promote(Context c, Expression e, Token token) {
return new ProcessedThrowStatement(c, e, token, stack, thrownExceptionType, exceptionData); return new ProcessedThrowStatement(c, e, token, stack, type, data);
} }
} }