Skip to content

Commit

Permalink
Removed try-with-resources
Browse files Browse the repository at this point in the history
  • Loading branch information
mlambert125 committed Jan 22, 2025
1 parent 57eb895 commit 6641bca
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 70 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ To get started, open the project file located in
## Project Overview

This project contains a `Main` class that contains several methods that
demonstrate various aspects of error handling in Java. There are two other
demonstrate various aspects of error handling in Java. There is one other
supporting classes in the project:

1. The `FakeFileReader` class is a fake implementation of a file reader that is
used to demonstrate how to handle exceptions in Java. *You **WILL NOT** Need
to modify this class.*
2. The `CustomDivideByZeroException` class is a custom exception that is thrown
1. The `CustomDivideByZeroException` class is a custom exception that is thrown
when a division by zero is attempted. *You **WILL** need to modify this
class.*

Expand Down
40 changes: 0 additions & 40 deletions src/main/java/org/example/FakeFileReader.java

This file was deleted.

14 changes: 1 addition & 13 deletions src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,13 @@ public static double safeDivision(double a, double b) {
* @return The second letter of the string
*/
public static String getSecondLetter(String s, List<String> logMessages) {
// TODO: Handle the StringINdexOutOfBoundsException by returning an empty string ("")
// TODO: Handle the StringIndexOutOfBoundsException by returning an empty string ("")
return s.substring(1, 2);

// TODO: This line needs to happen after the try/catch block, regardless of whether an exception is thrown (use a finally block)
// logMessages.add("Exiting method");
}

/**
* Read a fake file and return its contents.
*
* @param logMessages List of log messages to add to
* @return The contents of the faked file
*/
public static String readFile(List<String> logMessages) {
// TODO: Initialize the FakeFileReader in a try-with-resources block to make sure it closes and updates the logMessages list
FakeFileReader reader = new FakeFileReader(logMessages);
return reader.read();
}

/**
* Safely divide two numbers. If the denominator is zero, it will return 0.
*
Expand Down
12 changes: 0 additions & 12 deletions src/test/java/ExerciseTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,6 @@ public void testGetSecondLetter() {
assertEquals(1, logMessages.size());
}

/**
* Test the readFile method.
*/
@Test
public void testReadFile() {
var logMessages = new java.util.ArrayList<String>();
var result = Main.readFile(logMessages);

assertEquals("Hello world", result);
assertEquals(1, logMessages.size());
}

/**
* Test the safeDivideWithCustomException method.
*/
Expand Down

0 comments on commit 6641bca

Please sign in to comment.