Skip to content
Permalink
Browse files
Create AbstractCompileException
This exception should be used as parent exception for compile exceptions, and can be useful to handle any compile exception in a single catch clause.
  • Loading branch information
Pieter12345 committed Jul 21, 2020
1 parent 0b00fc7 commit f44e6f58b58e6baa0fee80450fa3a1f3e73fdb1b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
@@ -0,0 +1,24 @@
package com.laytonsmith.core.exceptions;

/**
* This abstract {@link Exception} should be used as super class for exceptions that are thrown to indicate that
* compilation has failed.
*/
@SuppressWarnings("serial")
public abstract class AbstractCompileException extends Exception {

public AbstractCompileException() {
}

public AbstractCompileException(String message) {
super(message);
}

public AbstractCompileException(String message, Throwable cause) {
super(message, cause);
}

public AbstractCompileException(Throwable cause) {
super(cause);
}
}
@@ -5,10 +5,10 @@
import java.util.Objects;

/**
*
*
* This {@link Exception} can be thrown when a problem occurs during compilation.
*/
public class ConfigCompileException extends Exception implements Comparable<ConfigCompileException> {
@SuppressWarnings("serial")
public class ConfigCompileException extends AbstractCompileException implements Comparable<ConfigCompileException> {

final String message;
final int lineNum;
@@ -40,28 +40,28 @@ public ConfigCompileException(ConfigRuntimeException e) {

@Override
public String getMessage() {
return message;
return this.message;
}

public String getLineNum() {
return Integer.toString(lineNum);
return Integer.toString(this.lineNum);
}

public int getColumn() {
return col;
return this.col;
}

public Target getTarget() {
return t;
return this.t;
}

@Override
public String toString() {
if(lineNum != 0) {
return "Configuration Compile Exception: " + message + " near line " + lineNum + ". Please "
if(this.lineNum != 0) {
return "Configuration Compile Exception: " + this.message + " near line " + lineNum + ". Please "
+ "check your code and try again. " + (file != null ? "(" + file.getAbsolutePath() + ")" : "");
} else {
return "Configuration Compile Exception: " + message + ". Please check your code and try again. "
return "Configuration Compile Exception: " + this.message + ". Please check your code and try again. "
+ (file != null ? "(" + file.getAbsolutePath() + ")" : "");
}
}
@@ -4,17 +4,20 @@
import java.util.TreeSet;

/**
*
* This {@link Exception} can be used to bundle multiple {@link ConfigCompileException}s together for cases were
* multiple compile exceptions have occurred during compilation.
*/
public class ConfigCompileGroupException extends Exception {
@SuppressWarnings("serial")
public class ConfigCompileGroupException extends AbstractCompileException {

private final Set<ConfigCompileException> list;

public ConfigCompileGroupException(Set<ConfigCompileException> group) {
super();
this.list = new TreeSet<>(group);
}

public Set<ConfigCompileException> getList() {
return new TreeSet<>(list);
return new TreeSet<>(this.list);
}
}

0 comments on commit f44e6f5

Please sign in to comment.