Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[W7.6][T16-2] Ang Jie Liang #202

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/seedu/addressbook/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ private void runCommandLoopUntilExitCommand() {
do {
String userCommandText = ui.getUserCommand();
command = new Parser().parseCommand(userCommandText);
CommandResult result = executeCommand(command);
recordResult(result);
ui.showResultToUser(result);

try {
CommandResult result = executeCommand(command);
recordResult(result);
ui.showResultToUser(result);
} catch (StorageOperationException e){
ui.showToUser(e.getMessage());
}
} while (!ExitCommand.isExit(command));
}

Expand All @@ -104,13 +107,17 @@ private void recordResult(CommandResult result) {
*
* @param command user command
* @return result of the command
* @throws StorageOperationException if modify readonly files.
*/
private CommandResult executeCommand(Command command) {
private CommandResult executeCommand(Command command) throws StorageOperationException {
try {
command.setData(addressBook, lastShownList);
CommandResult result = command.execute();
storage.save(addressBook);
return result;
} catch(StorageOperationException e){
ui.showToUser(e.getMessage());
throw e;
} catch (Exception e) {
ui.showToUser(e.getMessage());
throw new RuntimeException(e);
Expand Down