• Post Reply Bookmark Topic Watch Topic
  • New Topic

thows?  RSS feed

 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public static void main(String args[]) throws IOexception



in this line what "thows" means ??? , strange thing is that there is no try , catch , finally in the program...... is that possible ???
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abhay jain wrote: in this line what "thows" means ??? , strange thing is that there is no try , catch , finally in the program...... is that possible ???

Yes it is possible.
It means that some part of the method might throw a IOException and the invoking method should handle the exception.

An useful related reply- http://www.coderanch.com/t/542239/java/java/Insight-exception-handling-please#2460115
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It just declares that it might throw an IOException. If you're unsure what that means I would suggest you read this.
 
Badal Chowdhary
Ranch Hand
Posts: 34
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Declaring throws clause means that you are aware that this method might throw an IOException but you don't want to handle it. If some other method calls this method that that method has to either handle it (try-catch) or again throw it.

In your case since the main method is throwing the exception, if the exception occurs the program will just print stacktrace and exit.

Thanks,
Badal
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Badal Chowdhary wrote: . . . an IOException but you don't want to handle it. . . .
Correct. If your Exception originates in this method you should usually not catch it in the same method.

Bad:That is just a very inefficient way to write an if-else block

Good:Then a calling method can tell that the method has not worked, because there is an Exception.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!