The previous article introduced how to quickly add try/catch statements for non-checked exceptions. Here we will add some other related operations. Sometimes we need to add a Finally block after adding a try/catch. For example, we recommend that you add a Finally block at the end of the Code for every allocation of a cursor on Android, and disable cursor to prevent memory leakage. The total memory usage of cursor on Android is 2 MB. If the high-frequency method of the app does not close cursor in time, it will cause other modules to fail to allocate cursor. Next we will introduce how to add quick operations for finally blocks.
Step 1: based on the previous article, add the try/catch statement and place the cursor in the try line:
Step 2: press Ctrl + 1 to add the Finally block:
Finally, add some other things: place the cursor on the line of the try statement, press Ctrl + 1 to add a Finally block, and place the cursor on the line of catch, press Ctrl + 1 to delete the try/catch statement. These operations also work for adding for and while loop blocks. You can try them yourself.
In the previous article, eclipse usage and technique 8: automatically add try/Catch Block 1:
Http://blog.csdn.net/ts1122/article/details/8886219
Next article, eclipse usage and tips 10: Show Code outline:
Http://blog.csdn.net/ts1122/article/details/8933207