+ 1
Why do we need throw clause in java?
When java system implicitly can throw and catch exception using try/catch block, then why do we need a separate throw clause to explicitly throw an exception
3 Réponses
+ 2
think..u r working in a company...after few days u left the job...now ur boss told the programmer if anyone type his name..it should show an exception...So manually he is throwing an exception..
+ 1
Sometimes you want to have your own exceptions and throw them accordingly
+ 1
Well java only throws exception that are already in Exception class. However, the exception that are user defined need the programmer to define a condition in which exception needs to be thrown. Java does not know the conditions in which user defined exception needs to be thrown so we have to explicitly type throw exceptionName to achieve the goal.