Skip to content

Commit

Permalink
205: ignoring exceptions
Browse files Browse the repository at this point in the history
Task-Url: #205
  • Loading branch information
LorenzoBettini committed Aug 25, 2022
1 parent a95cd0e commit 078dc39
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
import org.pitest.pitclipse.core.PitCoreActivator;
import org.pitest.pitclipse.launch.ui.utils.PitclipseLaunchUiUtils;
import org.pitest.pitclipse.runner.config.PitConfiguration;

import java.util.List;
Expand Down Expand Up @@ -108,24 +109,19 @@ public void launch(ISelection selection, String mode) {
}

private void launch(Object[] elements, String mode) {
try {
PitclipseLaunchUiUtils.executeSafely(() -> {
if (elements.length == 1) {
Optional<IJavaElement> selected = asJavaElement(elements[0]);
Optional<IJavaElement> launchElement =
selected.flatMap(this::getLaunchElementFor);

if (launchElement.isPresent()) {
performLaunch(launchElement.get(), mode);
}
}
else {
} else {
showNoTestsFoundDialog();
}
} catch (InterruptedException e) { // NOSONAR
// OK, silently move on
} catch (CoreException e) { // NOSONAR
// OK, silently move on
}
});
}

private void showNoTestsFoundDialog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public static interface RunnableWithCoreException {
void run() throws CoreException;
}

@FunctionalInterface
public static interface RunnableWithCoreExceptionInterruptable {
void run() throws CoreException, InterruptedException;
}

/**
* Executes the passed lambda and in case of {@link CoreException} sets the
* error message.
Expand All @@ -49,4 +54,19 @@ public static void executeSafely(RunnableWithCoreException runnable, PitMutators
configurationTab.setErrorMessage(ce.getStatus().getMessage());
}
}

/**
* Executes the passed lambda and ignores exceptions.
*
* @param runnable
*/
public static void executeSafely(RunnableWithCoreExceptionInterruptable runnable) {
try {
runnable.run();
} catch (InterruptedException e) { // NOSONAR
// OK, silently move on
} catch (CoreException e) { // NOSONAR
// OK, silently move on
}
}
}

0 comments on commit 078dc39

Please sign in to comment.