Skip to content

Commit

Permalink
Make loadAprilTagFieldLayout throw an unchecked exception instead
Browse files Browse the repository at this point in the history
  • Loading branch information
rzblue committed Sep 14, 2023
1 parent 57b2d6f commit f2b0a62
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ public static AprilTagFieldLayout loadFromResource(String resourcePath) throws I
try (InputStream stream = AprilTagFieldLayout.class.getResourceAsStream(resourcePath);
InputStreamReader reader = new InputStreamReader(stream)) {
return new ObjectMapper().readerFor(AprilTagFieldLayout.class).readValue(reader);
} catch (NullPointerException e) {
// Class.getResourceAsStream() returns null if the resource does not exist.
throw new IOException("Could not locate resource: " + resourcePath + "\n");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package edu.wpi.first.apriltag;

import java.io.IOException;
import java.io.UncheckedIOException;

public enum AprilTagFields {
k2022RapidReact("2022-rapidreact.json"),
Expand All @@ -25,9 +26,13 @@ public enum AprilTagFields {
* Get a {@link AprilTagFieldLayout} from the resource JSON.
*
* @return AprilTagFieldLayout of the field
* @throws IOException If the layout does not exist
* @throws UncheckedIOException If the layout does not exist
*/
public AprilTagFieldLayout loadAprilTagLayoutField() throws IOException {
return AprilTagFieldLayout.loadFromResource(m_resourceFile);
public AprilTagFieldLayout loadAprilTagLayoutField() {
try {
return AprilTagFieldLayout.loadFromResource(m_resourceFile);
} catch (IOException e) {
throw new UncheckedIOException("Could not load AprilTagFieldLayout from " + m_resourceFile, e);
}
}
}

0 comments on commit f2b0a62

Please sign in to comment.