Create a Java program to demonstrate the use of an interface for a custom exception
class MyException extends Exception { public MyException(String message) { super(message); } } interface ExceptionLogger { void logException(Exception e); } class Logger implements ExceptionLogger { @Override public void logException(Exception e) { System.out.println("Logging Exception : " + e.getMessage()); } } public class Main { public static void main(String[] args) { ExceptionLogger logger = new Logger(); try { throw new MyException("Custom Exception"); } catch (Exception e) { logger.logException(e); } } }
Logging Exception : Custom Exception
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions