The Artima Developer Community
Sponsored Link

Java Answers Forum
don't understand why checked exceptions get swallowed.

2 replies on 1 page. Most recent reply: Jul 25, 2003 1:49 AM by Dor

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Dor

Posts: 13
Nickname: eis
Registered: Jul, 2003

don't understand why checked exceptions get swallowed. Posted: Jul 25, 2003 12:44 AM
Reply to this message Reply
Advertisement
I am currently reading the book Thinking in Java. I don't get a clue why sometimes checked exceptions could get swallowed, from the examples in the book´.

Please please help!


Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: don't understand why checked exceptions get swallowed. Posted: Jul 25, 2003 1:32 AM
Reply to this message Reply
In the following example, the declaration statement must be surrounded by the try/catch construct because the FileNotFound exception must be handled.
        try
        {
            FileInputStream fis = new FileInputStream("ImportantFile");
        }
        catch (FileNotFoundException e)
        {
            // ToDo.  Handle the file exception here.
            // (Perhaps it will never happen.  Do nothing.)
        }

The exception is caught in the catch section but all that section contains is a comment. Nothing is done to handle the exception, thus it is 'swallowed'. The compiler is happy and the code will execute but if an exception did occur it would be ignored and the code following may well fall over in an ungy - and perhaps difficult to debug - heap because it assumed that it was in possesion of a valid FileInputStream object.

Incidentally; Bruce has a lot to say about the pros and cons of checked exceptions on his web site www.mindwiew.com. However, I would make sure you are happy with exceptions in your own head before you look at it, since both the case against them that he puts and the ensuing debate would be somewhat confusing to a beginner.

Vince.

PS. Isn't finding never done 'todo' comments in other people's code an uplifting experience. Not. :(

Dor

Posts: 13
Nickname: eis
Registered: Jul, 2003

Re: don't understand why checked exceptions get swallowed. Posted: Jul 25, 2003 1:49 AM
Reply to this message Reply
Thx! Clear now.

Flat View: This topic has 2 replies on 1 page
Topic: JavaMail Previous Topic   Next Topic Topic: Issues in Java browser

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use