sujesh Katri wrote:my brother wrote throw new NullPointerException("...");....is it correct or not....i think he must be write System.out.println("...")throws NullPointerException;thanks
He can do this because NullPointerException is an unchecked exception.
The syntax you proposed is illegal. Keyword
throws belongs to a signature of a method (a method definition), not the method call.
sujesh Katri wrote:my lecturer said we always write throw inside the method only and when we write throw in the method body then we must be write throws in the context of method heading..please tell me.
That is correct except for unchecked exceptions. See
this.