• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

thows?

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ???
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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- https://coderanch.com/t/542239/java/java/Insight-exception-handling-please#2460115
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 34
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79786
382
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
What do you have to say for yourself? Hmmm? Anything? And you call yourself a tiny ad.
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic