Community
Participate
Working Groups
It would be handy to have an action that takes a block of code and wraps it in a try/finally clause. This could be implemented by defining a new template var (say ${code}) that equals the block of code that's selected when the template is invoked. This would involve a new way of invoking templates: when a block of code is selected and code assist is activated, it shows a list of 'wrapping templates' (those with ${code} in it). This would allow for a simple form of user definable formatting rules. So a try/finally template would be defined thus: try { ${code} } finally { } Note that the formatter would have to apply the indent before ${code} to all lines in the code block. Just an idea. In any case, a try/finally tool would be handy.
to be considered after 2.0
[refactoring] As an alternative we can provide an action similar to Surround with try/catch. Consider for 2.1
On reflection, that would probably be the best way to go from a UI perspective. However I still like my 'wrapping template' idea, but I'll raise a seperate FR for it.
in 2.1 select lines to surround, ctrl + 1 and you will see all templates that contain the variables ${line_selection} do, while, try are defined by default , but you can also define your own surrounding templates.
*** Bug 64677 has been marked as a duplicate of this bug. ***
While this does work (and thanks, since I never used the templates before), nonetheless there are 2 ways of creating a try/catch block, templates and the context menu, and since a try/finally block is analogous to a try/catch, I think this issue warrants similar handling. Besides not all users are ex/current vi/emacs users and enjoy the cryptic key bindings. Some are propbably like me and use the context menu more than anything else. This issue should be reopend and menu item added.