This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception in main

 
Mauro Mazzucco
Ranch Hand
Posts: 32
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why this code compiles fine?
Main is throwing a Exception and noone catchs it, why the compiler doesnt complain?
 
Ramesh Pramuditha Rathnayake
Ranch Hand
Posts: 178
2
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's caught by JVM..
 
Konstantinos Alvertis
Greenhorn
Posts: 11
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code compiles fine . ( You don't have any syntax error etc ...)

With the

you declare that main method may throw an Exception.


In order to throw the exception add throw new Exception();



As Ramesh said the exception are caught at Runtime by JVM.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A related one at - What does it mean when the main method throws an exception?

Regards,
Dan
 
M Shareef
Greenhorn
Posts: 6
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code is fine it is printing the "hi" to the console.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic