java-commons/muscript/src/main/java/io/gitlab/jfronny/muscript/data/dynamic/DynamicTypeConversionExcept...

22 lines
918 B
Java

package io.gitlab.jfronny.muscript.data.dynamic;
import io.gitlab.jfronny.muscript.compiler.CodeLocation;
import io.gitlab.jfronny.muscript.error.LocationalException;
public class DynamicTypeConversionException extends RuntimeException {
private static final String MESSAGE1 = "Could not convert dynamic of type ";
private static final String MESSAGE2 = " to ";
private final String target;
private final String actual;
public DynamicTypeConversionException(String target, Dynamic dynamic) {
super(MESSAGE1 + (dynamic == null ? "null" : dynamic.getClass().getSimpleName()) + MESSAGE2 + target);
this.target = target;
this.actual = dynamic == null ? "null" : dynamic.getClass().getSimpleName();
}
public LocationalException locational(CodeLocation location) {
return new LocationalException(location, MESSAGE1 + actual + MESSAGE2 + target, this);
}
}