Skip to content

Commit a17007a

Browse files
committed
feat: updated exception in lesson14 homework by Yemi
1 parent 2264a0c commit a17007a

File tree

3 files changed

+4
-13
lines changed

3 files changed

+4
-13
lines changed

lesson_14/exceptions/exceptions_app/src/main/java/com/codedifferently/lesson14/ecommerce/EcommerceSystem.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void addProduct(String productId, String name) {
2020
public String placeOrder(String productId, int quantity) throws ProductNotFoundException {
2121
Product product = products.get(productId);
2222
if (product == null) {
23-
throw new ProductNotFoundException("Product with ID 1 not found");
23+
throw new ProductNotFoundException("Product with ID " + productId + " not found");
2424
}
2525
String orderId = UUID.randomUUID().toString();
2626
orders.put(orderId, new Order(orderId, product, quantity));
@@ -30,9 +30,10 @@ public String placeOrder(String productId, int quantity) throws ProductNotFoundE
3030
public void cancelOrder(String orderId) throws OrderNotFoundException {
3131
Order order = orders.get(orderId);
3232
try {
33-
if (order == null) throw new OrderNotFoundException("Such Order does not exist");
33+
if (order == null)
34+
throw new OrderNotFoundException("Order with order ID " + orderId + " does not exist");
3435
} catch (OrderNotFoundException e) {
35-
System.out.println(" Order does not exist");
36+
System.out.println("Order with order ID " + orderId + " does not exist");
3637
}
3738
orders.remove(orderId);
3839
}

lesson_14/exceptions/exceptions_app/src/main/java/com/codedifferently/lesson14/ecommerce/OrderNotFoundException.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/*
2-
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3-
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
4-
*/
5-
61
package com.codedifferently.lesson14.ecommerce;
72

83
class OrderNotFoundException extends RuntimeException {

lesson_14/exceptions/exceptions_app/src/main/java/com/codedifferently/lesson14/ecommerce/ProductNotFoundException.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/*
2-
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3-
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
4-
*/
5-
61
package com.codedifferently.lesson14.ecommerce;
72

83
class ProductNotFoundException extends RuntimeException {

0 commit comments

Comments
 (0)