Try, catch, finally, autocomplete template in IntelliJ

Using IntelliJ , when I type try followed by Ctrl-Space (autocomplete), I don't add anything

Instead, I would like to see

  try { // do something great } catch { case e: Exception => // handle me } 

Scala language, if that matters.

How can I define an autocomplete pattern as shown above?

+6
source share
2 answers

Use surround templates :

surround

You can find more details in the help:

+11
source

Yes, you can go to File > Settings... and under Live Templates add your own, Abbreviation: try

Template text:

 try { // do something great } catch { case e: Exception => $END$ // handle me } 

Used in Java: expression. $VAL$ places the cursor there after turning off "try".

+4
source

All Articles