• 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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: 179
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: 25831
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: 904
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.

 
Every time you till, you lose 30% of your organic matter. But this tiny ad is durable:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic