"throw" is a keyword for creating our own Exception or CustomException. for Example if you are going for ATM you need 10000 bugs, but your account has 1000 bugs then if you are not using this "throw" it will show "404 Server Error".Instead of displaying server specific errors use this "throw" keyword. Ex: class ThrowDemo{ static void validate(int age){ if(age<18) throw new ArithmeticException("not valid"); else System.out.println("welcome to vote"); } public static void main(String args[]){ validate(13); System.out.println("rest of the code..."); } } "throws" keyword is used to declare an exception. It gives an information to the programmer that there may occur an exception so it is better for the programmer to provide the exception handling code so that normal flow can be maintained. Ex: void method_name() throws exception_class_name{ ... } | 3 |
By: [email protected] On: Mon Nov 11 22:16:44 EST 2013 0 3 0 | 3 |
Are You Satisfied :4Yes2No |
1)throw is used to explicitly throw an exception. throws is used to declare an exception. 2)checked exception can not be propagated without throws. checked exception can be propagated with throws. 3)throw is followed by an instance. throws is followed by class. 4)throw is used within the method. throws is used with the method signature. 5)You cannot throw multiple exception You can declare multiple exception e.g. public void method()throws IOException,SQLException. | 3 |
By: [email protected] On: Tue Nov 12 00:29:34 EST 2013 0 359 0 | 359 |
Are You Satisfied :6Yes2No |