Skip to content

Commit

Permalink
OpelLogicalExpressionException extracted
Browse files Browse the repository at this point in the history
  • Loading branch information
bgalek committed Dec 22, 2020
1 parent 0483450 commit 190d927
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,15 @@ private <T> T wrappingExceptionsWithOpelException(Object left, Supplier<T> wrapp
try {
return wrappedBody.get();
} catch (Exception e) {
String msg = String.format("Error on evaluating left side of logical expression. " +
"operator: '%s', left: '%s', class: '%s'",
logicalOperator, left, left.getClass());
throw new OpelException(msg, e);
throw new OpelLogicalExpressionException(logicalOperator, left, e);
}
}

private <T> T wrappingExceptionsWithOpelException(Object left, Object right, Supplier<T> wrappedBody) {
try {
return wrappedBody.get();
} catch (Exception e) {
String msg = String.format("Error on evaluating logical expression. " +
"operator: '%s', left: '%s', class: '%s' right: '%s', class: '%s'",
logicalOperator, left, left.getClass(), right, right.getClass());
throw new OpelException(msg, e);
throw new OpelLogicalExpressionException(logicalOperator, left, right, e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package pl.allegro.tech.opel;

public class OpelLogicalExpressionException extends OpelException {

public OpelLogicalExpressionException(Operator logicalOperator, Object left, Exception exception) {
super(getMessage(logicalOperator, left), exception);
}

public OpelLogicalExpressionException(Operator logicalOperator, Object left, Object right, Exception exception) {
super(getMessage(logicalOperator, left, right), exception);
}

private static String getMessage(Operator logicalOperator, Object left) {
return String.format(
"Error on evaluating left side of logical expression. " +
"Operator: '%s', left: '%s', class: '%s'",
logicalOperator, left, left.getClass());
}

private static String getMessage(Operator logicalOperator, Object left, Object right) {
return String.format(
"Error on evaluating logical expression. " +
"Operator: '%s', left: '%s', class: '%s' right: '%s', class: '%s'",
logicalOperator, left, left.getClass(), right, right.getClass());
}
}

0 comments on commit 190d927

Please sign in to comment.