From the compiler perspective, exceptions in Java can be divided into two types: checked exceptions and unchecked exceptions. For checked exceptions such as IO operations, the compiler requires that you set the try/catch statement block. In eclipse, you only need to use the help shortcut Ctrl + 1 to automatically generate try/catchCode. For unchecked exceptions, the compiler does not require you to add protection blocks, and the IDE help shortcut does not work. Powerful eclipse also provides us with the ability to automatically generate try/catch.
Step 1: select the code that requires try/catch protection, pay attention to the complete line, and right-click:
Step 2: Select surround with and then select try/Catch Block:
Step 3: complete:
Note that the selected code should be in the unit of an entire statement on the Code. Generally, one row is a statement, so we have to select one line above.
PreviousArticle, Eclipse usage and tips 7: automatically generate get and Set Method 2:
Http://blog.csdn.net/ts1122/article/details/8893263
In the next article, eclipse usage and technique 9: automatically add try/Catch Block 2:
Http://blog.csdn.net/ts1122/article/details/8933196