http://www.jindent.com |
|
Next: Presets |
Brace style for try-catch statements |
Left brace { new line |
try-catch
statements appears in a new line
or not.
try { ... |
try { ... |
Right brace } new line |
try-catch
statements appears in a new line
or not.
try { ... } catch(Exception e) { ... } |
try { ... } catch(Exception e) { ... } |
Indent left brace { |
try ····{ ····... |
try { ... |
try·{ ... |
try{ ... |
Indent right brace } |
try ····{ ····... ····} catch(Exception·e)· ····{ ····... ····} |
try { ····... } catch(Exception·e)· { ····... } |
Indent after right brace } |
try-catch
statements.
try { ... }catch(Exception e) { ... } |
try { ... } catch(Exception e) { ... } |
Cuddle braces of empty blocks {} |
try-catch
statement blocks.
try { ... } catch(Exception e) {} |
try { ... } catch(Exception e) { } |
Indent cuddled braces {} |
try·{ ... }·catch(Exception·e){} |
try·{ ... }·catch(Exception·e)·{} |
Prohibit blank lines after left brace { |
try-catch
statement blocks.try-catch
statement blocks
an unecessary gap can appear.
try { ¶ // comment with a preceding blank line callAnotherMethod(); ¶ // another comment ... } catch(Exception e) { ... } |
try { // comment with a preceding blank line callAnotherMethod(); ¶ // another comment ... } catch(Exception e) { ... } |
See also: | Jindent - Settings - Formatter - Java / SQLJ - Blank Lines - Comments , Jindent - Settings - Formatter - Java / SQLJ - Blank Lines |
If number of lines in body is at least ... then insert blank line after { |
try-catch
statements
containing a certain number of lines in their bodies.
try { callMethod(); } catch(Exception e) System.err.println(e); } ¶ try { callMethodA(i); for (int i = 0; i < n; i++) { callMethodB(i); callMethodC(i); } callMethodD(i); } catch(Exception e) { // print error System.err.println(e); } |
try-catch
statement looks fine,
but the second try-catch
statement seems to be formatted too close:
The try {
statement the first block statement
callMethodA(i);
are connected too close and could cause confusion.
try-catch
statements use setting
"If number of lines in body is at least ... then insert blank line after {" to insert an extra blank line before the first
block statement.
try { callMethod(); } catch(Exception e) System.err.println(e); } ¶ try { ¶ callMethodA(i); for (int i = 0; i < n; i++) { callMethodB(i); callMethodC(i); } callMethodD(i); } catch(Exception e) { ¶ // print error System.err.println(e); } |
try-catch
statement seems to be much clearer and the
first try-catch
statement is still formatted as before.try-catch
statement and if at least
2 lines are counted then an extra blank line is inserted after the left brace of try-catch
statement block.try-catch
statements can be kept compact, but try-catch
statements with an extended body are formatted more spacious and clearer.
try { callMethod(); } catch(Exception e) System.err.println(e); } ¶ try { ¶ callMethodA(i); for (int i = 0; i < n; i++) { callMethodB(i); callMethodC(i); } callMethodD(i); } catch(Exception e) { // print error System.err.println(e); } |
catch
part of the second statement is formatted in a more compact way too.
try { ¶ callMethod(); } catch(Exception e) ¶ System.err.println(e); } ¶ try { ¶ callMethodA(i); for (int i = 0; i < n; i++) { callMethodB(i); callMethodC(i); } callMethodD(i); } catch(Exception e) { ¶ // print error System.err.println(e); } |
try-catch
statements are formatted more spacious.infinite
.If number of lines in body is at least ... then insert blank line before } |
try { callMethod(); } catch(Exception e) System.err.println(e); } ¶ try { ¶ callMethodA(i); for (int i = 0; i < n; i++) { callMethodB(i); callMethodC(i); } callMethodD(i); ¶ } catch(Exception e) { ¶ // print error System.err.println(e); ¶ } |
Do not insert blank line before single left brace |
try { // <- this right brace appears alone callMethodA(); callMethodB(); } catch(Exception e) { // <- this right brace does not appear alone callMethodC(); callMethodC(); } // <- this right brace appears alone |
} catch(Exception e)
does not appear alone,
it is directly followed by an catch
token.
try { callMethod(); } catch(Exception e) System.err.println(e); } ¶ try { ¶ callMethodA(i); for (int i = 0; i < n; i++) { callMethodB(i); callMethodC(i); } callMethodD(i); ¶ } catch(Exception e) { ¶ // print error System.err.println(e); ¶ } |
try
block of the second try-catch
statement, but for the catch
block an extra blank line seems to be unnecessary.
try { callMethod(); } catch(Exception e) System.err.println(e); } ¶ try { ¶ callMethodA(i); for (int i = 0; i < n; i++) { callMethodB(i); callMethodC(i); } callMethodD(i); ¶ } catch(Exception e) { ¶ // print error System.err.println(e); } |
} catch(Exception e) {
because this is the
only case a right braces does not appear as a single brace.See also: | Jindent - Settings - Formatter - Java / SQLJ - Braces Style - Presets |