Commit 66b514b3 authored by Bhargavi Ghanta's avatar Bhargavi Ghanta

Task 10 completed: Hierarchical error handling with layered services

parent b99e6388
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="ms-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/CustomException.iml" filepath="$PROJECT_DIR$/CustomException.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
public class BusinessServiceLayer {
private DataAccessLayer dal = new DataAccessLayer();
public void processBusinessLogic() throws CustomException {
System.out.println("Business logic started...");
dal.fetchData(); // Exception will bubble up from here
System.out.println("Business logic completed.");
}
}
public class ControllerLayer {
private BusinessServiceLayer service = new BusinessServiceLayer();
public void handleRequest() throws CustomException {
System.out.println("Request received by controller...");
service.processBusinessLogic(); // Exception may bubble up to here
System.out.println("Response sent successfully.");
}
}
public class CustomException extends Exception {
public CustomException(String message) {
super(message);
}
}
public class DataAccessLayer {
public void fetchData() throws CustomException {
// Simulate failure
throw new CustomException("Database connection failed");
}
}
public class Main {
<<<<<<< HEAD
public static void processPaymentMethod(String method, String offer) {
PaymentService paymentService = new PaymentService();
......@@ -20,4 +21,15 @@ public class Main {
processPaymentMethod("card", "UPI10"); // invalid offer for card
processPaymentMethod("upi", "UPI10"); // valid
}
=======
public static void main(String[] args) {
ControllerLayer controller = new ControllerLayer();
try {
controller.handleRequest();
} catch (CustomException e) {
System.err.println("Error handled in Main: " + e.getMessage());
}
}
>>>>>>> 6db3119 (Add Task 10: Hierarchical error handling implementation)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment