Search code examples
intellij-idea

"Wrap with try...catch" in IntelliJ?


Can I select a block of code and have IntelliJ wrap it with a "try...catch" ?

Is there a keyboard shortcut?


Solution

  • Select the code, and then either:

    • Choose Code > Surround With
    • Press Ctrl+Alt+T. (⌘ Command+⌥ Option+T for OS X.)

    From time to time, I like to check the Productivity Guide via the Help > My Productivity menu item. Not only does it tell me all the shortcuts, but it keeps track of how many times I've used each one and when I last used it. I can see how well I'm leveraging the shortcuts.