• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

io questions

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 clause.

Can anyone explain this to me??
thanks~~
 
Ranch Hand
Posts: 3143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I would answer d since java.lang.Exception is extended by java.io.IOException ... EOFException extends IOExeption but may not be the specific exception thrown so if you caught that I don't think it would compile. Also I think in this case you would not use a throw statement to throw an IOException.
I think all this question is testing is your knowledge of the API ... ie... which class extends which.
[This message has been edited by Angela Poynton (edited January 05, 2001).]
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Angela, I think it is D also.
A. - False EOFException is a subclass of IOException so you are not throwing the entire exception, just part of it.
B. - False Would be true if this was throws statement, but not a throw statement. You throw new exceptions, and you use throws to pass the exception to the where the method was called.
C. - False, same as A.
D. - True, Exception is a superclass of IOException, so if you catch this then you are catching all of IOException.
Bill
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic