Add general KiwiException that other Exceptions extend

This commit is contained in:
Alex Birkett 2016-01-31 12:43:20 +01:00
parent fc14835bab
commit 88307a9f06
11 changed files with 30 additions and 14 deletions

View File

@ -3,9 +3,11 @@ package no.birkett.kiwi;
/**
* Created by alex on 30/01/15.
*/
public class DuplicateConstraintException extends Exception {
public class DuplicateConstraintException extends KiwiException {
private Constraint constraint;
public DuplicateConstraintException(Constraint constraint) {
this.constraint = constraint;
}
}

View File

@ -3,6 +3,6 @@ package no.birkett.kiwi;
/**
* Created by yongsun on 1/13/16.
*/
public class DuplicateEditVariableException extends Exception {
public class DuplicateEditVariableException extends KiwiException {
}

View File

@ -3,7 +3,7 @@ package no.birkett.kiwi;
/**
* Created by alex on 31/01/15.
*/
public class InternalSolverError extends RuntimeException {
public class InternalSolverError extends Error {
public InternalSolverError(String string) {

View File

@ -0,0 +1,10 @@
package no.birkett.kiwi;
/**
* Created by alex on 30/01/16.
*/
public class KiwiException extends Exception {
public KiwiException() {
}
}

View File

@ -3,5 +3,5 @@ package no.birkett.kiwi;
/**
* Created by alex on 01/02/15.
*/
public class NonlinearExpressionException extends RuntimeException {
public class NonlinearExpressionException extends KiwiException {
}

View File

@ -3,5 +3,5 @@ package no.birkett.kiwi;
/**
* Created by alex on 30/01/15.
*/
public class RequiredFailureException extends Exception {
public class RequiredFailureException extends KiwiException {
}

View File

@ -3,7 +3,7 @@ package no.birkett.kiwi;
/**
* Created by yongsun on 1/13/16.
*/
public class UnknownConstraintException extends Exception {
public class UnknownConstraintException extends KiwiException {
public UnknownConstraintException(Constraint constraint){

View File

@ -3,8 +3,10 @@ package no.birkett.kiwi;
/**
* Created by alex on 30/01/15.
*/
public class UnsatisfiableConstraintException extends Exception {
public UnsatisfiableConstraintException(Constraint constraint) {
public class UnsatisfiableConstraintException extends KiwiException {
private Constraint constraint;
public UnsatisfiableConstraintException(Constraint constraint) {
this.constraint = constraint;
}
}

View File

@ -7,7 +7,7 @@ import java.util.HashMap;
*/
public class Benchmarks {
public static void testAddingLotsOfConstraints() throws DuplicateConstraintException, UnsatisfiableConstraintException {
public static void testAddingLotsOfConstraints() throws DuplicateConstraintException, UnsatisfiableConstraintException, NonlinearExpressionException {
Solver solver = new Solver();
final HashMap<String, Variable> variables = new HashMap<String, Variable>();
@ -65,6 +65,8 @@ public class Benchmarks {
e.printStackTrace();
} catch (UnsatisfiableConstraintException e) {
e.printStackTrace();
} catch (NonlinearExpressionException e) {
e.printStackTrace();
}
}

View File

@ -19,7 +19,7 @@ public class ConstraintParser {
Expression resolveConstant(String name);
}
public static Constraint parseConstraint(String constraintString, CassowaryVariableResolver variableResolver) {
public static Constraint parseConstraint(String constraintString, CassowaryVariableResolver variableResolver) throws NonlinearExpressionException {
Matcher matcher = pattern.matcher(constraintString);
matcher.find();
@ -63,7 +63,7 @@ public class ConstraintParser {
return strength;
}
public static Expression resolveExpression(String expressionString, CassowaryVariableResolver variableResolver) {
public static Expression resolveExpression(String expressionString, CassowaryVariableResolver variableResolver) throws NonlinearExpressionException {
List<String> postFixExpression = infixToPostfix(tokenizeExpression(expressionString));

View File

@ -202,7 +202,7 @@ public class RealWorldTests {
}
@Test
public void testGridLayout() throws DuplicateConstraintException, UnsatisfiableConstraintException {
public void testGridLayout() throws DuplicateConstraintException, UnsatisfiableConstraintException, NonlinearExpressionException {
final Solver solver = new Solver();
final HashMap<String, HashMap<String, Variable>> nodeHashMap = new HashMap<>();
@ -321,7 +321,7 @@ public class RealWorldTests {
*/
@Test
public void testGridX1000() throws DuplicateConstraintException, UnsatisfiableConstraintException {
public void testGridX1000() throws DuplicateConstraintException, UnsatisfiableConstraintException, NonlinearExpressionException {
long nanoTime = System.nanoTime();
for (int i = 0; i < 1000; i++) {