================================================================================================= == MyException.java ================================================================================================= package user_defined_exception; public class MyException extends Exception { public MyException(String s) { // Call constructor of parent Exception super(s); } } ================================================================================================= == ExceptionTest.java ================================================================================================= public class ExceptionTest { public static void main(String[] args) { // TODO Auto-generated method stub try { // Throw an object of user defined exception throw new MyException("GeeksGeeks"); } catch (MyException ex) { System.out.println("Caught"); // Print the message from MyException object System.out.println(ex.getMessage()); } } } ================================================================================================= == StockAttrNameNotFoundException.java ================================================================================================= public class ExceptionTest { package user_defined_exception; public class StockAttrNameNotFoundException extends Exception { public StockAttrNameNotFoundException(String s) { // Call constructor of parent Exception super(s); } public String getDetailedMsg( String in_attr_name ) { String msg = "Stock attribute name not found !!!" + in_attr_name ; return msg; } } ================================================================================================= == ExceptionTest.java ================================================================================================= package user_defined_exception; public class ExceptionTest { public static void main(String[] args) { // TODO Auto-generated method stub try { // Throw an object of user defined exception throw new StockAttrNameNotFoundException("GeeksGeeks"); } catch (StockAttrNameNotFoundException ex) { System.out.println("Caught"); // Print the message from MyException object System.out.println(ex.getMessage()); System.out.println(ex.getDetailedMsg( "weekly_rate" )); } } }