What's the Java style for formatting a long throws
list?
Let's say I have this:
public void some() throws IOException, ClassNotFoundException, NoSuchMethodException,InvocationTargetException, IllegalAccessException {
}
Should it be:
public void some()
throws IOException,
ClassNotFoundException,
NoSuchMethodException,
InvocationTargetException,
IllegalAccessException {
}
,
public void some() throws IOException,ClassNotFoundException,
NoSuchMethodException,InvocationTargetException,
IllegalAccessException {
}
Or something else?
The old java code conventions would argue against the first one, as it extends past 80 characters.
Avoid lines longer than 80 characters, since they're not handled well by many terminals and tools.
The Java code convention does not distinguish between long throws
and other reasons for long method signatures. I would suggest that the second and third are equivalent because they both:
I would vote for the former, as it is easier to read. To be honest, I'd hate to come across that method.
The real rule of thumb, of course, is to follow the code convention of the team you are working in. If they all use editors that can support 81+ character lines and prefer non-wrapped lines to save vertical real estate, that should be formatting style you use.
I would prefer the second version, it is clear and readable. One item per line.
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