• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Exceptions

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Given that a java.io.IOException might occur when calling the read() method of the BufferedInputStream, you can handle the exception by:
a) Listing a java.io.EOFException in a throws list.
b) Catch the java.lang.Exception using the throw statement.
c) Catch a java.io.EOFException using a try/catch clause.
d) Catch a java.lang.Exception using a try/catch 3
I think 1 & 3 should be the right choices....
Can anyone help....?
Thx in adv.
Aruna
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of the answers you listed, only d is correct. The read() methods throws IOException. The hierarchy is
Throwable - Exception - IOException - EOFException.
To catch an exception, it either has to that type or a superclass of that type so, trying to catch IOException with EOFException wouldn't work.
 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Aru:
Hi all,
Given that a java.io.IOException might occur when calling the read() method of the BufferedInputStream, you can handle the exception by:
a) Listing a java.io.EOFException in a throws list.
b) Catch the java.lang.Exception using the throw statement.
c) Catch a java.io.EOFException using a try/catch clause.
d) Catch a java.lang.Exception using a try/catch 3
I think 1 & 3 should be the right choices....
Can anyone help....?
Thx in adv.
Aruna



I think the answer is d. only. EOFException is one of the subclasses of IOException, there are many more subclasses. Hence, it is not enough to catch it. java.lang.Exception, on the other hand, is parent of IOException, so IOException and all its children can be caught by this try/catch block.
Isn't that right?
Savithri
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic