+ 3

what is the deference between "throw" and "throws"

throws & throw

28th Jun 2017, 1:31 AM
yassou
yassou - avatar
4 Respuestas
+ 2
throws is part of the method signature indicating the compiler that the underlying method throws an exception. The compiler then enforces each of the method's client handle the exception through a try catch finally block. throw is part of the method definition or body. when the runtime goes through the execution path where it sees a throw statement, the method is terminated and it's caller is returned the exception. From there it is the caller's job to handle the exception.
28th Jun 2017, 1:41 AM
Venkatesh Pitta
Venkatesh Pitta - avatar
+ 2
Remember two things "throws" ---> To define exception (It tells compiler that this peace of code may have exception,but it can be possible there is no exception.It is just define the exception) "throw"--> To throw exception forcefully.Suppose there is no exception in your peace of code but still u want to throw a exception(most of the time self created exception) and handle it through "catch".
28th Jun 2017, 1:59 AM
Saikat Mukherjee
Saikat Mukherjee - avatar
+ 2
thank you very much
28th Jun 2017, 2:01 AM
yassou
yassou - avatar
+ 2
throw raises the exception . throws populate the exception to calling function
15th Nov 2017, 6:24 AM
Rkumar
Rkumar - avatar