Reputation: 2998
In Eclipse, when I enter code Thread.sleep(100)
, the code will be wrappered by try catch after entering keys: ctrl+1 and enter. In Android studio what can I do for wrapper it by try catch easily? Is there a shortcut?
Upvotes: 37
Views: 49933
Reputation: 1
type try and press tab button, it will create try/catch template easily
Upvotes: 0
Reputation: 829
Short Cut of Generating predefined/custom templates
Press Ctrl + Alt + T
Surround with many blocks like
Upvotes: 0
Reputation: 6384
Select the code you want to surround with try/catch and press Alt + Shift + Z, this will bring up try/catch along with any other applicable templates like this:
To generate a try/catch block type 'try' and press ctrl + space.
The Ctrl + Shift + T shortcut launches the terminal in the eclipse version I am using - 2019-03.
Upvotes: 1
Reputation: 1153
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.
Upvotes: 16
Reputation: 1481
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.
Upvotes: 84
Reputation: 7793
In Ubuntu Gnome, Ctrl + Alt + T has been taken already by "Launch terminal", run command gnome-control-center keyboard
to check:
Either you disable it by press Back Space
OR use Ctrl + Alt + Win + T as alternative.
Keep in mind that if "try / catch" option doesn't shows up, it might caused by warning such as "unexpected token" in your code. You need to fix it first.
Upvotes: 8
Reputation: 691
Short Cut of Generating predefined/custom templates
Press Ctrl + Alt + T
Upvotes: 0
Reputation: 6961
On Mac it's: cmd + alt + T. Also for most used shortcuts in Android Studio I'd recommend this link http://www.developerphil.com/android-studio-tips-of-the-day-roundup-2/
Upvotes: 3
Reputation: 151
Type "try",
then press alt + ctrl + t,
then select "try / catch".
Upvotes: 8
Reputation: 411
Try this
Upvotes: 7