DekGenius.com
Previous Section  < Day Day Up >  Next Section

Recipe 3.11 Surrounding Code with do/for/if/try/while Blocks

3.11.1 Problem

You want to enclose a section of code in a try/catch block or in a do/for/if/while construct.

3.11.2 Solution

Select the lines to surround, press Ctrl-1 (or select Edit Quick Fix) to list all the possibilities, and select one of them.

3.11.3 Discussion

Figure 3-14 shows the possibilities that appear when you select code and press Ctrl-l. When you select one of these possibilities, the selected code becomes surrounded with the construct you've chosen.

Figure 3-14. Surrounding code in a block
figs/ecb_0314.gif


One of the great things here is that if you surround your code with a try/catch block in this way, Eclipse automatically figures out all the possible exceptions and catches them for you.


3.11.4 See Also

Chapter 2 of Eclipse (O'Reilly).

    Previous Section  < Day Day Up >  Next Section