Explain about the 'throws' keyword ?

#2
Someone told me, that using 'throws' keyword along with main() is not recommended in real time?


Is it correct approach?

why ?
If the method is unable to handle the exception then we use throws keyword along with the method.
Syntax: datatype method-name(parameters list) throws exception1,exception2...
 
#3
Be careful when you use the throws keyword. It means that the user of your methods will need to worry about it. If your main() method throws exceptions it could mean that its caller may have problems with it and your program can crash. Remember that if you throw an exception then you must catch it as well.
 
Top