Customize catch block in Java and enable smart insert in Eclipse

customization, eclipse, java, try-catch

Solution

Yes it's possible, open Eclipse Preference and then `Java > Code Style > Code Templates`. There you select `Code > Catch block body`. Here you can edit your `try/catch` block.

Add `myCustomLogger.LogMe(Log.getStackTraceString(${exception_var}));`

Problem

In Eclipse when we select code statements and right click on it, it gives us an option for surrounding with `try/catch` block, after selecting this option our code looks like. ``` try { //selected code lines } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } ``` Now I want to define a custom catch block which should look like below after selecting surround with `try/catch` block from eclipse smart insert: ``` try { //selected code lines } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); myCustomLogger.LogMe(Log.getStackTraceString(e)); } ``` Is it possible? Does Eclipse allow us to customize some properties for specific project in smart insert?

Original source