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);
Goto Android Studio Preferences
| Editor
| File and Code Templates
Select Code
| Catch Statement Body
Replace the existing template from:
${EXCEPTION}.printStackTrace();
with:
Log.e(getClass().getSimpleName(), "Exception handled", ${EXCEPTION});
Preview:
Enjoy the customized template :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With