User defined exception in Java User defined exceptions in java are also known as Custom exceptions . Most of the times when we are developing an application in java, we often feel a need to create and throw our own exceptions. These exceptions are known as User defined or Custom exceptions. In this tutorial we will see how to create and throw such exceptions in a java program. Example of User defined exception in Java class MyException extends Exception { String str1 ; MyException ( String str2 ) { str1 = str2 ; } public String toString (){ return ( "Output String = " + str1 ) ; } } class CustomException { public static void main ( String args []){ try { throw new MyException ( "Custom" ); // I'm throwing user defined custom exception above } catch ( MyException exp ){ System . out . print...
IF YOU CAN DREAM IT. YOU CAN ACHIEVE IT.