Logging Exceptions Example

This program demonstrates logging exceptions using stack trace.

Problem Statement

Write a Java program that logs exceptions using printStackTrace().

Source Code

1 public class LoggingExceptionExample {
2 public static void main(String[] args) {
3 System.out.println("Eduinq Logging Exception Example");
4 try {
5 int result=10/0;
6 } catch(Exception e) {
7 System.out.println("Eduinq Exception Logged:");
8 e.printStackTrace();
9 }
10 }
11 }

Program Output

					Eduinq Logging Exception Example
Eduinq Exception Logged:
java.lang.ArithmeticException: / by zero
    at LoggingExceptionExample.main(LoggingExceptionExample.java:5)
				

Explanation

Logging exceptions provides detailed error information. - printStackTrace() shows exception type, message, and stack trace. - Improves debugging and monitoring. - In enterprise systems, logging is critical for error analysis and auditing. Conclusion: Shows logging exceptions with stack trace.

Quick Links to Explore