Modify non-Live template "Surround With" snippet

I often use "Surround with try/catch" from the "Intention Actions" menu to surround a method call with try and the appropriate checked exception catch blocks. There are two things I have been unable to change in this generated code.

1) The generated exception variable does not have the final modifier. None of the normal code generation "enable final" options seem to affect this.
2) The name of the generated exception variable. It is always "e" I would like to change it.

Am I missing some options, or is this currently not possible? One option I was contemplating was to create a new "Surround with" live template. Would this work?

Thanks.

2 comments
Comment actions Permalink

You can modify the code inside the catch block's braces (Settings > [IDE Settings] > File and Code Templates > [Code tab]  > "Catch Statement Block"). However, I do not believe the full surround with template is editable. I believe it is defined within the intention. So it looks like you will need to define a custom surround with.

You may want to vote for and track the bug report IDEA-125327 "Surround with try/catch" code generation seems to not respect final modifier settings.

I'd recommend commenting on IDEA-116670 "Surround with try/catch" - exception variable name "ex" in catch blocks instead "e" to ask that the code generation template be editable.

0
Comment actions Permalink

Fantastic. I will do both of those things, and remember to look more closely at the bug tracker in the future. Thank you!

0

Please sign in to leave a comment.