| Author |
main() method throws exception
|
venkatesh pendharkar
Ranch Hand
Joined: Apr 29, 2006
Posts: 104
|
|
hi I would like to know how come main() method can throws exception eg. public static void main(String[] args) throws InterruptedException { throw new InterruptedException(); } if main() method throws exception then who catches it??JVM??Can anyone please explain me the logic behind it.
|
 |
Krishna Srinivasan
Ranch Hand
Joined: Jul 28, 2003
Posts: 1803
|
|
If an exception is always handled using the throws clause, then eventually the exception will propagate all the way back to the main method of the application. If the main method throws the exception and the exception actually occurs while the program is running, then the program will crash. See this link for more details : http://www.cs.wisc.edu/~cs302/io/Exceptions.html
|
Krishna Srinivasan
OCAJP Mock Questions
|
 |
venkatesh pendharkar
Ranch Hand
Joined: Apr 29, 2006
Posts: 104
|
|
|
Thanks Krishna for your reply
|
 |
Cherry Singhal
Greenhorn
Joined: Sep 05, 2006
Posts: 6
|
|
Hi krishna, So that means nothing catches the exception? & by crashing you mean we get a corresponding runtime exception?
|
 |
 |
|
|
subject: main() method throws exception
|
|
|