+ 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

31st Jan 2017, 7:55 PM
Ratnadeep Dey
Ratnadeep Dey - avatar
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..
1st Feb 2017, 5:30 AM
Somnath Ghosh
Somnath Ghosh - avatar
+ 1
Sometimes you want to have your own exceptions and throw them accordingly
31st Jan 2017, 10:07 PM
Jannick
+ 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.
1st Feb 2017, 9:47 PM
Nimit Patel
Nimit Patel - avatar