Skip to content

Commit

Permalink
Changed where FileNotFoundException is wrapped in an UncheckedFileNot…
Browse files Browse the repository at this point in the history
…FoundException when reading from file
  • Loading branch information
Nikollai committed May 24, 2026
1 parent ff73c1b commit 1e156e1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/main/java/millions/controller/GameController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package millions.controller;

import java.io.FileNotFoundException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.file.Path;
Expand Down Expand Up @@ -38,7 +39,7 @@ public void startGame(

player = new Player(name, startingMoney);

} catch (UncheckedFileNotFoundException e) {
} catch (FileNotFoundException e) {
throw new UncheckedFileNotFoundException(e.getMessage());
} catch (InvalidFormatException e) {
throw new InvalidFormatException(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import millions.model.Stock;


import java.io.FileNotFoundException;
import java.nio.file.Path;
import java.util.List;

Expand All @@ -28,7 +29,7 @@ public CSVFileHandler() {
* @throws InvalidFormatException Throws an InvalidFormatException received from parser
* @throws UncheckedFileNotFoundException Upon Receiving a FilenotFoundException
*/
public List<Stock> getStocksFromFile(Path filePath) {
public List<Stock> getStocksFromFile(Path filePath) throws FileNotFoundException {
try {
StockFileReader reader = new StockFileReader();
List<String> lines = reader.readFile(filePath);
Expand All @@ -38,8 +39,8 @@ public List<Stock> getStocksFromFile(Path filePath) {

} catch (InvalidFormatException e) {
throw new InvalidFormatException(e.getMessage());
} catch (UncheckedFileNotFoundException e) {
throw new UncheckedFileNotFoundException(e.getMessage());
} catch (FileNotFoundException e) {
throw new FileNotFoundException(e.getMessage());
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/millions/controller/fileIO/StockFileReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public StockFileReader() {}
* @return List of each line in the file as a string
* @throws UncheckedFileNotFoundException Upon encountering a FileNotFoundException
*/
public List<String> readFile(Path path) {
public List<String> readFile(Path path) throws FileNotFoundException {
File file = new File(path.toString());
List<String> lines = new ArrayList<>();
try (Reader reader = new FileReader(file);
Expand All @@ -34,7 +34,7 @@ public List<String> readFile(Path path) {
}
} catch (IOException e) {
if (e instanceof FileNotFoundException) {
throw new UncheckedFileNotFoundException("Couldn't find file at specified path");
throw new FileNotFoundException("Couldn't find file at specified path");
}
else {
logger.log(Level.SEVERE, "Encountered unexpected IOException: ", e.getMessage());
Expand Down

0 comments on commit 1e156e1

Please sign in to comment.