Reputation: 7636
I'm trying to set up Eclipse so that it formats a try catch finally block (when pressing CTRL+SHIFT+F
as follows:
try
{
// some code
}
catch (IOException exception)
{
// some exception handling code
}
finally
{
// some more code
}
I found the formatting options under Window >> Preferences >> Java >> Code Style >> Formatter and added a new Active profile, however I can't see an option for try catch blocks on the braces tab. I've set everything on that tab to "Next line", however the code now formats as:
try
{
// some code
} catch (IOException exception)
{
// some exception handling code
} finally
{
// some more code
}
Upvotes: 4
Views: 4730
Reputation: 11
You may go to this https://help.eclipse.org/latest/index.jsp?topic=%2Forg.eclipse.jdt.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fjdt%2Fcore%2Fformatter%2FDefaultCodeFormatterConstants.html then hit Ctrl + F searching for the phrases below:
"org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement"
"org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement"
You may find out how to configure the settings. If not, here is the xml file that I used:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="13">
<profile kind="CodeFormatterProfile" name="myProfile" version="13">
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="insert" />
Upvotes: 1
Reputation: 19443
You have to do it in two places:
Upvotes: 7
Reputation: 8362
The settings you need are in the Control Statements
tab:
Upvotes: 9