Skip to content

Commit

Permalink
Update error handling for release
Browse files Browse the repository at this point in the history
  • Loading branch information
nubnubyas committed Sep 20, 2023
1 parent ffd8585 commit 91c0539
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
Binary file modified data/duke.txt
Binary file not shown.
4 changes: 3 additions & 1 deletion src/main/java/monday/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Duration;

import monday.monday.ui.Ui;

/**
Expand All @@ -31,6 +30,9 @@ public class MainWindow extends AnchorPane {
private Image userImage = new Image(this.getClass().getResourceAsStream("/images/bai.png"));
private Image mondayImage = new Image(this.getClass().getResourceAsStream("/images/fa.png"));

/**
* Start the programme and greets the user on start of program.
*/
@FXML
public void initialize() {
dialogContainer.getChildren().add(DialogBox.getDukeDialog(Ui.greet(), mondayImage));
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/monday/Monday.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ private void startMonday() {
System.out.println(p.parseCommands(userInput));
} catch (MondayException e) {
Ui.printErrorMessage("", e);
} catch (NumberFormatException e) {
Ui.printErrorMessage("Mark/UnMark number error: ", e);
} catch (IllegalArgumentException e) {
Ui.printErrorMessage("Argument Error: ", e);
} catch (IndexOutOfBoundsException e) {
Ui.printErrorMessage("Index out of Bound Error: ", e);
}
Ui.printSeparator();
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/monday/monday/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private String deadLineCommand(String content) throws MondayException {

return taskList.addToList(new Deadline(description.trim(), date.trim()));
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("Invalid Format. "
throw new MondayException("Invalid Format. "
+ "Usage: deadline (task) /by (time)");
}
}
Expand Down Expand Up @@ -190,7 +190,7 @@ private String eventCommand(String content) throws MondayException {
start.trim(),
end.trim()));
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("Invalid Format. "
throw new MondayException("Invalid Format. "
+ "Usage: event (task) /from (start time) /to (end time)");
}
}
Expand Down Expand Up @@ -229,7 +229,7 @@ private String findCommand(String content) throws MondayException {
String[] keywordDetails = content.split(" ");

if (keywordDetails.length > 1) {
throw new IllegalArgumentException("Invalid Format. "
throw new MondayException("Invalid Format. "
+ "Usage: find (keyword), there should only be one keyword.");
}

Expand Down
19 changes: 10 additions & 9 deletions src/main/java/monday/task/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.util.ArrayList;

import monday.monday.exception.MondayException;
import monday.monday.ui.Ui;
import monday.storage.TaskArrayListStorage;

Expand Down Expand Up @@ -71,12 +72,12 @@ public String toString() {
*
* @param index The index of the task to be marked as done.
* @return Message after marking the task as done.
* @throws IndexOutOfBoundsException If the index is out of range.
* @throws MondayException If the index is out of range.
*/
public String mark(int index) {
public String mark(int index) throws MondayException {
assert !tasks.isEmpty() : "Your task list is empty, please add more elements.";
if (index < 1 || index > tasks.size()) {
throw new IndexOutOfBoundsException("Task index is out of range. "
throw new MondayException("Task index is out of range. "
+ "Check the number of tasks using the 'list' command.");
}
Task taskToEdit = tasks.get(index - 1);
Expand All @@ -90,12 +91,12 @@ public String mark(int index) {
*
* @param index The index of the task to be marked as not done.
* @return Message after marking the task as not done.
* @throws IndexOutOfBoundsException If the index is out of range.
* @throws MondayException If the index is out of range.
*/
public String unMark(int index) {
public String unMark(int index) throws MondayException {
assert !tasks.isEmpty() : "Your task list is empty, please add more elements.";
if (index < 1 || index > tasks.size()) {
throw new IndexOutOfBoundsException("Task index is out of range. "
throw new MondayException("Task index is out of range. "
+ "Check the number of tasks using the 'list' command.");
}
Task taskToEdit = tasks.get(index - 1);
Expand All @@ -109,12 +110,12 @@ public String unMark(int index) {
*
* @param index The index of the task to be deleted.
* @return Message after deleting the task.
* @throws IndexOutOfBoundsException If the index is out of range.
* @throws MondayException If the index is out of range.
*/
public String delete(int index) {
public String delete(int index) throws MondayException {
assert !tasks.isEmpty() : "Your task list is empty, please add more elements.";
if (index < 1 || index > tasks.size()) {
throw new IndexOutOfBoundsException("Task index is out of range. "
throw new MondayException("Task index is out of range. "
+ "Check the number of tasks using the 'list' command.");
}
Task taskToEdit = tasks.get(index - 1);
Expand Down

0 comments on commit 91c0539

Please sign in to comment.