How to generate a try catch code block automatic in Android Studio by shortcut?

Highlight the code you want to surround with try/catch

For Windows it is:

Press Ctrl + Alt + t

For Mac it is:

Press cmd + Alt + t

Select the item you want (#7 for try / catch)

There is no need to "type" try first however, highlighting your code works better.


Highlight the necessary code you need to surround with, and press one of the key combinations depending upon your Operating System.

Windows: Ctrl + Alt + T

Linux(Ubuntu): Ctrl + Windows + Alt + T

Mac: Cmd + Alt + T

A list of Surround With options would pop (like in the below image). You can select the appropriate item of your choice either by pressing the respective number of the item on keyboard or manually via mouse click.

Surround With