Skip to content

Commit

Permalink
Don't catch Exception class
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada committed May 1, 2024
1 parent a386f1e commit 8620692
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/JavaFxApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import java.lang.ProcessHandle.Info;
import java.nio.file.Paths;
import java.time.*;
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalTime;
import java.time.YearMonth;
import java.util.Arrays;
import java.util.Optional;
import java.util.concurrent.ScheduledExecutorService;
Expand All @@ -17,8 +21,13 @@
import org.itsallcode.whiterabbit.jfxui.ui.AppUi;
import org.itsallcode.whiterabbit.jfxui.ui.InterruptionDialog;
import org.itsallcode.whiterabbit.jfxui.uistate.UiStateService;
import org.itsallcode.whiterabbit.logic.*;
import org.itsallcode.whiterabbit.logic.model.*;
import org.itsallcode.whiterabbit.logic.Config;
import org.itsallcode.whiterabbit.logic.ConfigLoader;
import org.itsallcode.whiterabbit.logic.DefaultWorkingDirProvider;
import org.itsallcode.whiterabbit.logic.WorkingDirProvider;
import org.itsallcode.whiterabbit.logic.model.Activity;
import org.itsallcode.whiterabbit.logic.model.DayRecord;
import org.itsallcode.whiterabbit.logic.model.MonthIndex;
import org.itsallcode.whiterabbit.logic.service.AppService;
import org.itsallcode.whiterabbit.logic.service.AppServiceCallback;
import org.itsallcode.whiterabbit.logic.service.singleinstance.OtherInstance;
Expand Down Expand Up @@ -56,7 +65,8 @@ public JavaFxApp()
this(new DefaultWorkingDirProvider(), Clock.systemDefaultZone(), new ScheduledThreadPoolExecutor(1));
}

JavaFxApp(WorkingDirProvider workingDirProvider, Clock clock, ScheduledExecutorService executorService)
JavaFxApp(final WorkingDirProvider workingDirProvider, final Clock clock,
final ScheduledExecutorService executorService)
{
this.workingDirProvider = workingDirProvider;
this.clock = clock;
Expand All @@ -70,14 +80,14 @@ public void init()
{
doInitialize();
}
catch (final Exception e)
catch (final RuntimeException e)
{
stop();
throw e;
}
}

private void notifyPreloaderProgress(Type notificationType)
private void notifyPreloaderProgress(final Type notificationType)
{
notifyPreloader(new ProgressPreloaderNotification(this, notificationType));
}
Expand Down Expand Up @@ -113,7 +123,7 @@ private Config loadConfig()
}

@Override
public void start(Stage primaryStage)
public void start(final Stage primaryStage)
{
this.primaryStage = primaryStage;
state.setPrimaryStage(primaryStage);
Expand All @@ -122,7 +132,7 @@ public void start(Stage primaryStage)
notifyPreloaderProgress(Type.STARTUP_FINISHED);
}

private void doStart(Stage primaryStage)
private void doStart(final Stage primaryStage)
{
this.ui = new AppUi.Builder(this, actions, appService, primaryStage, state).build();

Expand Down Expand Up @@ -193,7 +203,8 @@ private void startAppService()
appService.start();
}

private void messageFromOtherInstanceReceived(String message, RunningInstanceCallback.ClientConnection client)
private void messageFromOtherInstanceReceived(final String message,
final RunningInstanceCallback.ClientConnection client)
{
if (MESSAGE_BRING_TO_FRONT.equals(message))
{
Expand Down Expand Up @@ -268,15 +279,15 @@ public void startManualInterruption()
private final class AppServiceCallbackImplementation implements AppServiceCallback
{
@Override
public InterruptionDetectedDecision automaticInterruptionDetected(LocalTime startOfInterruption,
Duration interruption)
public InterruptionDetectedDecision automaticInterruptionDetected(final LocalTime startOfInterruption,
final Duration interruption)
{
return JavaFxUtil
.runOnFxApplicationThread(() -> showAutomaticInterruptionDialog(startOfInterruption, interruption));
}

private InterruptionDetectedDecision showAutomaticInterruptionDialog(LocalTime startOfInterruption,
Duration interruption)
private InterruptionDetectedDecision showAutomaticInterruptionDialog(final LocalTime startOfInterruption,
final Duration interruption)
{
final Alert alert = createAlertDialog(startOfInterruption, interruption);
LOG.info("Showing automatic interruption alert starting at {} for {}...", startOfInterruption,
Expand All @@ -287,7 +298,7 @@ private InterruptionDetectedDecision showAutomaticInterruptionDialog(LocalTime s
return decision;
}

private Alert createAlertDialog(LocalTime startOfInterruption, Duration interruption)
private Alert createAlertDialog(final LocalTime startOfInterruption, final Duration interruption)
{
final Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Interruption detected");
Expand Down Expand Up @@ -315,15 +326,15 @@ private InterruptionDetectedDecision evaluateButton(final Optional<ButtonType> s
return InterruptionDetectedDecision.SKIP_INTERRUPTION;
}

private boolean isButton(Optional<ButtonType> button, ButtonData data)
private boolean isButton(final Optional<ButtonType> button, final ButtonData data)
{
return button.map(ButtonType::getButtonData)
.filter(d -> d == data)
.isPresent();
}

@Override
public void recordUpdated(DayRecord day)
public void recordUpdated(final DayRecord day)
{
final YearMonth month = YearMonth.from(day.getDate());
JavaFxUtil.runOnFxApplicationThread(() -> {
Expand All @@ -339,22 +350,22 @@ public void recordUpdated(DayRecord day)
});
}

private boolean daySelected(DayRecord dayRecord)
private boolean daySelected(final DayRecord dayRecord)
{
final Optional<DayRecord> selectedDay = state.getSelectedDay();
return selectedDay.isPresent() && selectedDay.get().getDate().equals(dayRecord.getDate());
}

@Override
public void exceptionOccurred(Exception e)
public void exceptionOccurred(final Exception e)
{
final String message = "An error occured: " + e.getClass() + ": " + e.getMessage();
LOG.error(message, e);
actions.showErrorDialog(message);
}

@Override
public void workStoppedForToday(boolean stopWorking)
public void workStoppedForToday(final boolean stopWorking)
{
JavaFxUtil.runOnFxApplicationThread(() -> state.stoppedWorkingForToday.setValue(stopWorking));
}
Expand Down

0 comments on commit 8620692

Please sign in to comment.