+ 2

Can someone explain me difference between 'throw' and 'throws' in Exception Handling? what is the need of 'throws'?

Would be great if someone explains with simple example.. Why do we need 'throws'? Why throw is not enough?

23rd Apr 2017, 8:09 PM
sahil soni
sahil soni - avatar
3 Antworten
+ 16
@throws is something like a warning. I'll try to explain it with methods: If you call a method that is annotated with @throws the compiler knows that this call must be surrounded by try/catch. throw is the keyword to actually throw a new exception in the method that is annotated with @throws.
23rd Apr 2017, 8:28 PM
Tashi N
Tashi N - avatar
+ 1
throws is a keyword that used to throw the runtime error to the os shell ,if you dont want to handle the error.
21st May 2017, 5:12 AM
Nandini Injarapu
Nandini Injarapu - avatar