Bug 107340 - [surround with try/catch] Surround with try/catch isn't nestable.
Summary: [surround with try/catch] Surround with try/catch isn't nestable.
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P4 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-18 13:04 EDT by Brian Miller CLA
Modified: 2006-06-16 14:58 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Miller CLA 2005-08-18 13:04:18 EDT
I want lines 4 and 6 to execute even if line 5 throws an exception.  So I 
select line 5 and use the Source menu to surround it with a try/catch block.  
But the generated catch block doesn't catch ClassNotFoundException, even 
though it's a checked exception thrown by line 5.

------------- Bug.java ----------------
class Bug {
    {
        try {
            Bug.class.getFields()[0].get(null); // LINE 4
            Class.forName("?");                 // LINE 5
            Bug.class.getFields()[0].get(null); // LINE 6
        } catch (Throwable crash) {
             crash.printStackTrace();
        }
    }
}
Comment 1 Dirk Baeumer CLA 2005-08-22 06:29:43 EDT
The reason is that the ClassNotFoundException is already catched by catch
(Throwable crash). The was a long discussion whether surround with should always
catch "all" exceptions or only those not catch by an outer block or propagated
by the method. Honoring both scenarios will require new UI. Simply changing it
will definitelly cause PRs complaining about the new behaviour.