Skip to content

Commit

Permalink
caught numberFormatException
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelory committed Apr 9, 2024
1 parent 56a762b commit 3554131
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/main/java/florizz/core/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,12 @@ private static AddFlowerCommand handleAddFlower(String argument, boolean enableU
String flowerName = argument.substring(0,quantityIndex).trim().toLowerCase();
String quantityString = removePrefix(argument.substring(quantityIndex, prefixIndex), QUANTITY).trim();
// [WARNING] might need to check if it's a valid integer
int quantity = Integer.parseInt(quantityString);
int quantity;
try {
quantity = Integer.parseInt(quantityString);
}catch(NumberFormatException error){
throw new FlorizzException("Invalid number inputted, please enter a sensible number next time!");
}
String bouquetName = removePrefix(argument.substring(prefixIndex), ADD_FLOWER_PREFIX).trim();
if (includeColour){
int colourIndex = argument.indexOf(COLOUR);
Expand Down Expand Up @@ -285,7 +290,12 @@ private static RemoveFlowerCommand handleRemoveFlower(String argument) throws Fl
String flowerName = argument.substring(0, quantityIndex).trim().toLowerCase();
String quantityString = removePrefix(argument.substring(quantityIndex, prefixIndex), QUANTITY).trim();
// [WARNING] might need to check if it's a valid integer
int quantity = Integer.parseInt(quantityString);
int quantity;
try {
quantity = Integer.parseInt(quantityString);
}catch(NumberFormatException error){
throw new FlorizzException("Invalid number inputted, please enter a sensible number next time!");
}
String bouquetName = removePrefix(argument.substring(prefixIndex), REMOVE_FLOWER_PREFIX).trim();
if (includeColour){
int colourIndex = argument.indexOf(COLOUR);
Expand Down

0 comments on commit 3554131

Please sign in to comment.