Each Android developer was stuck with the next situation:
public void catchMeThod() {
throwedMethod();
}
public void throwedMethod() throws IOException{
throw new IOException("File is missing.");
}
Since IOException
is Checked exception throwedMethod
obliges us to handle it.
When I move the caret inside throwedMethod
and press Alt + Enter , Android Studio offers me some possible scenarios:
By default I choose the Surround with try/catch
option and Android Studio generates the next code:
And my question is: how to change this trigger, to replace
e.printStackTrace()
with
Log.e(getClass().getSimpleName(), "Handled exception", e);
These "templates" are managed by Postfix Completion (Preferences > Editor > General > Postfix Completion > try
).
Sadly, these are hardcoded into the IDE and cannot be changed. The only way is to replace them manually.
Change only in current file
Press cmd + R (or control if you use windows/linux).
In the top bar enter the text to search for, in the bottom bar the text to replace it with. Then click replace all.
Change everywhere
In the project view, right click app and select "replace in path". Fill out the fields and click "find".
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.