• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

doubt in using throws keyword

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public static void method throws IOException{
                      thows FileNotFoundException();
}

is it valid?this question in my practise test?they answered it  as valid, because when using throws we can use superclass exception of the enclosing method exception.

can anyone please explain it clearly?Thanks.
 
Rancher
Posts: 167
7
Mac OS X IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Double-check if you copied it correctly, the way it is now it's not going to compile.
 
Raviteja Sankuratri
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah it should be throw in method
 
Marshal
Posts: 25594
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still not valid Java. If you want to ask a question about code from an outside source like a book, please copy the exact code into your question.

If the code you're asking about is on your computer in some way, then copy and paste it from where you're looking at it.

Showing us an approximate version of the code is not that helpful.
 
Rancher
Posts: 891
22
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raviteja,

it's really simple, you look at the ancestors of the class... as you bump back up the chain, each of the Super Classes has "is a" relationship to the subclass... so FileNotFoundExeption is a IOException and inherits the properties and methods from all of it's ancestors all the way back to Object so at the very top of the chain your get FileNotFoundException is a Object.  Each ancestor of FileNotFoundException has that "is a" type of relationship with FileNotFoundException.

Les

BTW: that relationship is true, regardless of the validity of the syntax of your code.

Raviteja Sankuratri wrote:public static void method throws IOException{
                      thows FileNotFoundException();
}

is it valid?this question in my practise test?they answered it  as valid, because when using throws we can use superclass exception of the enclosing method exception.

can anyone please explain it clearly?Thanks.

 
Time flies like an arrow. Fruit flies like a banana. Steve flies like a tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic