Skip to content
Snippets Groups Projects
Commit 4c6fe37c authored by Harry Linrui XU's avatar Harry Linrui XU
Browse files

Potentially caught exception in the correct manner

parent f793ae51
No related branches found
No related tags found
5 merge requests!43Merging frontend-testing into master,!38"Made progressbar dynamic in accordance to spending. Added balance field....,!37Made the sub progress bars respond to changes in expense,!32Added input validation to add dialog boxes.,!31Added input validation to tableviews
...@@ -167,9 +167,11 @@ public class AddExpenseController { ...@@ -167,9 +167,11 @@ public class AddExpenseController {
private void addEventFilters() { private void addEventFilters() {
okBtn.addEventFilter( okBtn.addEventFilter(
ActionEvent.ACTION, event -> { ActionEvent.ACTION, event -> {
if (!validateInputs()) { try {
event.consume(); validateInputs();
errorMsg.setOpacity(1); } catch(IllegalArgumentException e) {
event.consume();
errorMsg.setOpacity(1);
} }
}); });
} }
...@@ -179,8 +181,7 @@ public class AddExpenseController { ...@@ -179,8 +181,7 @@ public class AddExpenseController {
Double.parseDouble(amountField.getText()), recurringBox.getValue(), Double.parseDouble(amountField.getText()), recurringBox.getValue(),
categoryBox.getValue(), datePicker.getValue()); categoryBox.getValue(), datePicker.getValue());
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
System.out.println("ok"); throw new IllegalArgumentException("Invalid input. Cannot instantiate expense", e);
return false;
} }
return true; return true;
} }
......
...@@ -150,7 +150,9 @@ public class AddIncomeController { ...@@ -150,7 +150,9 @@ public class AddIncomeController {
private void addEventFilters() { private void addEventFilters() {
okBtn.addEventFilter( okBtn.addEventFilter(
ActionEvent.ACTION, event -> { ActionEvent.ACTION, event -> {
if (!validateInputs()) { try {
validateInputs();
} catch(IllegalArgumentException e) {
event.consume(); event.consume();
errorMsg.setOpacity(1); errorMsg.setOpacity(1);
} }
...@@ -162,8 +164,7 @@ public class AddIncomeController { ...@@ -162,8 +164,7 @@ public class AddIncomeController {
Double.parseDouble(amountField.getText()), recurringBox.getValue(), Double.parseDouble(amountField.getText()), recurringBox.getValue(),
categoryBox.getValue(), datePicker.getValue()); categoryBox.getValue(), datePicker.getValue());
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
System.out.println("ok"); throw new IllegalArgumentException("Invalid inputs. Cannot instantiate income", e);
return false;
} }
return true; return true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment