Skip to content

Commit

Permalink
Add error handling for negative indices
Browse files Browse the repository at this point in the history
  • Loading branch information
Asthenosphere committed Oct 3, 2020
1 parent b05a3c0 commit 088e3b4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/duke/command/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public DeleteCommand(int index) {
@Override
public String execute(TaskList tasks, Storage storage) throws DukeException {
try {
if (index > tasks.getSize()) {
if (index > tasks.getSize() || index < 0) {
throw new InvalidArgumentException(ARGUMENT_EXCEPTION);
}
String output = DELETE_MESSAGE;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/command/DoneCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public DoneCommand(int index) {
@Override
public String execute(TaskList tasks, Storage storage) {
try {
if (index > tasks.getSize()) {
if (index > tasks.getSize() || index < 0) {
throw new InvalidArgumentException("☹ OOPS!!! The task index you give is not found.");
}
if (tasks.markDone(index)) {
Expand Down

0 comments on commit 088e3b4

Please sign in to comment.