Skip to content
Snippets Groups Projects
Commit ac675b9c authored by Nelson Tavares de Sousa's avatar Nelson Tavares de Sousa
Browse files

introduced a flag which indicates if exceptions should be logged

parent 4c666ac8
No related branches found
No related tags found
No related merge requests found
......@@ -119,7 +119,7 @@ public abstract class Stage {
} catch (TerminateException e) {
throw e;
} catch (Exception e) {
final FurtherExecution furtherExecution = this.exceptionListener.onStageException(e, this);
final FurtherExecution furtherExecution = this.exceptionListener.reportException(e, this);
if (furtherExecution == FurtherExecution.TERMINATE) {
throw TerminateException.INSTANCE;
}
......
......@@ -31,6 +31,7 @@ import teetime.framework.Stage;
public abstract class AbstractExceptionListener {
private final List<Exception> exceptionsList = new ArrayList<Exception>();
private final boolean logExceptions;
public enum FurtherExecution {
CONTINUE, TERMINATE
......@@ -41,8 +42,9 @@ public abstract class AbstractExceptionListener {
*/
protected final Logger logger;
public AbstractExceptionListener() {
protected AbstractExceptionListener(final boolean shouldLogExceptions) {
this.logger = LoggerFactory.getLogger(this.getClass().getCanonicalName());
this.logExceptions = shouldLogExceptions;
}
/**
......@@ -61,4 +63,11 @@ public abstract class AbstractExceptionListener {
return exceptionsList;
}
public FurtherExecution reportException(final Exception e, final Stage stage) {
if (logExceptions) {
exceptionsList.add(e);
}
return onStageException(e, stage);
}
}
......@@ -19,6 +19,10 @@ import teetime.framework.Stage;
class IgnoringExceptionListener extends AbstractExceptionListener {
IgnoringExceptionListener() {
super(false);
}
@Override
public FurtherExecution onStageException(final Exception e, final Stage throwingStage) {
return FurtherExecution.CONTINUE;
......
......@@ -19,6 +19,10 @@ import teetime.framework.Stage;
class LoggingExceptionListener extends AbstractExceptionListener {
LoggingExceptionListener() {
super(true);
}
@Override
public FurtherExecution onStageException(final Exception e, final Stage throwingStage) {
logger.warn("Exception occurred in " + throwingStage.getId(), e);
......
......@@ -25,7 +25,7 @@ class TerminatingExceptionListener extends AbstractExceptionListener {
private final List<Exception> exceptions = new ArrayList<Exception>();
TerminatingExceptionListener() {
// should only be instantiated by its factory
super(true);
}
@Override
......
......@@ -19,6 +19,10 @@ import teetime.framework.Stage;
public class TestListener extends AbstractExceptionListener {
protected TestListener() {
super(false);
}
private int numExceptionsInvoked;
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment