+ 3
what is the deference between "throw" and "throws"
throws & throw
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.
+ 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".
+ 2
thank you very much
+ 2
throw raises the exception .
throws populate the exception to calling function