Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
#84 Replaced SWITCH with IF-ELSE statement and added a custom excepti…
Browse files Browse the repository at this point in the history
…on class to counter generic usage of exceptions
  • Loading branch information
abraredu11 committed Oct 13, 2023
1 parent b173c35 commit d069bb6
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@
import de.dennisguse.opentracks.data.ContentProviderUtils;
import de.dennisguse.opentracks.data.models.Track;


class UnknownResultCodeException extends Exception {
public UnknownResultCodeException() {
super("Unknown resultCode.");
}
}

public class TrackDeleteService extends JobIntentService {


private static final int JOB_ID = 3;

private static final String EXTRA_RECEIVER = "extra_receiver";
Expand Down Expand Up @@ -54,10 +62,18 @@ public TrackDeleteResultReceiver(Handler handler, @NonNull Receiver receiver) {

@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
switch (resultCode) {
case RESULT_CODE_SUCCESS -> receiver.onDeleteFinished();
default -> throw new RuntimeException("Unknown resultCode.");
if (resultCode == RESULT_CODE_SUCCESS) {
receiver.onDeleteFinished();
} else {
try {
throw new UnknownResultCodeException();
} catch (UnknownResultCodeException e) {


}
}


}

public interface Receiver {
Expand Down

0 comments on commit d069bb6

Please sign in to comment.