It's not a secret anymore!*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Indentation for Throws clause of a method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Indentation for Throws clause of a method" Watch "Indentation for Throws clause of a method" New topic
Author

Indentation for Throws clause of a method

Sam Codean
Ranch Hand

Joined: Feb 26, 2006
Posts: 194
Is this indentation correct as per Java Standards?
I mean can we align the Throws Clause right at the bottom of the Method Declaration?



-Sam Codean<br />SCJP 1.4 (98%)<br />SCJD 5.0 (87.5%)
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
See page 5 and 6 of the Java code conventions.
Subsequent indentation levels should indent 4 spaces from the previous indentation level, or 8 if that makes the code clearer.

In your case I'd use the following:


Far easier to read.


42
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
JTW++


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
next you're going to claim I posess multiple inheritance...
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11405
    
  81

JTW-- (Sorry Jeroen, you are back to your default value).

Section 4.2: Wrapping Lines of the Code Conventions gives two examples of indenting method declarations. Note that they indicate that the first example is the convential case. They also indicate that where the "rules lead to confusing code or to code that's squished up against the right margin, just indent 8 spaces instead."

So I would take that to mean:Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Sam Codean
Ranch Hand

Joined: Feb 26, 2006
Posts: 194
hmm thanks actually eclipse indents it that way so got confused.
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
Check out Eclipse's settings. It can be changed to reflect different coding guidelines set as several defaults.
It is quite possible that IBM likes this style, Sun likes another.
And for the assignment you'd better do things the way Sun likes them, even if you prefer to do things differently yourself.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
I still think JTW's is prettier Andrew, so JTW += JTW++ + JTW++ (to remind you guys of the good old SCJP days)
Sam Codean
Ranch Hand

Joined: Feb 26, 2006
Posts: 194
I still would prefer Andrew's Style as that makes it look more "as per Java Standards"
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
I admit that my style is more useful when there are so many exceptions that they no longer fit on a single line than in this scenario.
I also admit I don't follow it religiously, but then I'm called a heretic by most religions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Indentation for Throws clause of a method
 
Similar Threads
forced to lock and then read
NX: Should I call lock method before searching records?
Deadlock question
locking help
NX: More interface confusion.