This repository has been archived by the owner on Mar 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
model: convert checked exceptions to runtime exceptions (#896)
DuplicatePersonException and PersonNotFoundException are checked exceptions. They are thrown by methods to signify that their relevant preconditions were violated. Using checked exceptions for such a purpose is slightly useful in that it will force callers to handle the case where the above preconditions are not met, such as when the methods are called with invalid user input. However, it imposes a HUGE cost on callers where the preconditions are already known to be met (e.g. in test code, or when the user input has already been validated before hand). In such a case, callers are forced to add try-catch blocks around the method call even if they know that the exception will never be thrown, bloating up the code. It is also impossible to test the catch blocks as well since correct code will ensure that the precondition holds and thus the exception will never be thrown, leading to reduced code coverage. Checked exceptions also don't work very well with the Java Streams API, since the API doesn't accept lambdas which could throw checked exceptions. In AB-4, the amount of code which benefits from DuplicatePersonException and PersonNotFoundException being checked exceptions is much smaller than the amount of code which is negatively impacted. As such, let's make the tradeoff in the other direction, by making DuplicatePersonException and PersonNotFoundException runtime exceptions. New callers _could_ forget to check that the preconditions hold before calling the methods in question (although test cases should catch that), but this is balanced out by the huge benefit of having more concise and testable code. [1/11] Remove redundant throws clauses [2/11] model: expose hasPerson(Person) functionality [3/11] AddCommand: explicitly perform duplicate person check [4/11] EditCommand: explicitly perform duplicate person check [5/11] model: make DuplicatePersonException a RuntimeException [6/11] model: make PersonNotFoundException a RuntimeException [7/11] AddressBookSystemTest: remove unnecessary catch block [8/11] commons: remove DuplicateDataException [9/11] UniquePersonList: check for null arguments more thoroughly [10/11] UniquePersonListTest: move to `seedu.address.model.person` package [11/11] UniquePersonListTest: add some more tests
- Loading branch information
Showing
29 changed files
with
371 additions
and
202 deletions.
There are no files selected for viewing
10 changes: 0 additions & 10 deletions
10
src/main/java/seedu/address/commons/exceptions/DuplicateDataException.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
src/main/java/seedu/address/model/person/exceptions/DuplicatePersonException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.