diff --git a/Exception-Handling/src/customclass/com/CustomException.java b/Exception-Handling/src/customclass/com/CustomException.java new file mode 100644 index 0000000000000000000000000000000000000000..6825cb224a56596c109a664498faf772541748b2 --- /dev/null +++ b/Exception-Handling/src/customclass/com/CustomException.java @@ -0,0 +1,11 @@ +package customclass.com; + +class CustomException extends Exception { + String str; + CustomException(String str){ + this.str=str; + } + public String toString(){ + return ("Message " + str ); + } +} \ No newline at end of file diff --git a/Exception-Handling/src/customclass/com/UserDefined.java b/Exception-Handling/src/customclass/com/UserDefined.java new file mode 100644 index 0000000000000000000000000000000000000000..7a3feb27910e91b1d0eaa23a02501173d4699c7e --- /dev/null +++ b/Exception-Handling/src/customclass/com/UserDefined.java @@ -0,0 +1,22 @@ +package customclass.com; +public class UserDefined { + static void validation(String name) throws CustomException{ + + if (name == null){ + throw new CustomException(": Access Denied Due To Username or Password-----> Check Username & Password"); + } else { + System.out.println("-------- You Have Successfully Logined-----------"); + } + } + public static void main(String [] args){ + try { + validation(null); + } + catch (CustomException e){ + + System.out.println( e); + } + System.out.println("\n------------Custom-Exception---------------"); + } + +}