Bug 107340

Summary: [surround with try/catch] Surround with try/catch isn't nestable.
Product: [Eclipse Project] JDT Reporter: Brian Miller <bmiller>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: ASSIGNED --- QA Contact:
Severity: enhancement    
Priority: P4    
Version: 3.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

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.