Commit 82237d21 authored by Bhargavi Ghanta's avatar Bhargavi Ghanta

Resolve merge conflicts between local and remote

parents 787f8429 1954dd75
......@@ -2,7 +2,11 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<<<<<<< HEAD
<module fileurl="file://$PROJECT_DIR$/RetryUtility.iml" filepath="$PROJECT_DIR$/RetryUtility.iml" />
=======
<module fileurl="file://$PROJECT_DIR$/GlobalExceptionHandler.iml" filepath="$PROJECT_DIR$/GlobalExceptionHandler.iml" />
>>>>>>> 1954dd751dcf534a5ca8daa53b9ea31178d381eb
</modules>
</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
----- Exception Occurred -----
Thread: main
Exception: java.lang.ArithmeticException: / by zero
at GlobalExceptionLogger.divide(GlobalExceptionLogger.java:23)
at GlobalExceptionLogger.main(GlobalExceptionLogger.java:16)
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
public class GlobalExceptionLogger {
public static void main(String[] args) {
// Set up global exception handler
Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> {
logException(throwable);
});
// Sample code that throws an unhandled exception
System.out.println("Program started.");
int result = divide(10, 0); // This will cause ArithmeticException
System.out.println("Result: " + result);
}
// Method that may throw an exception
public static int divide(int a, int b) {
return a / b; // division by zero triggers an exception
}
// Method to log exceptions to a file
public static void logException(Throwable throwable) {
try (PrintWriter writer = new PrintWriter(new FileWriter("error.log", true))) {
writer.println("----- Exception Occurred -----");
writer.println("Thread: " + Thread.currentThread().getName());
writer.println("Exception: " + throwable);
for (StackTraceElement element : throwable.getStackTrace()) {
writer.println("\tat " + element);
}
writer.println(); // Blank line for separation
} catch (IOException e) {
System.err.println("Failed to log exception: " + e.getMessage());
}
}
}
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