Topics

Format of try ... catch blocks


Dave Heap
 

The "Format" command in NetBeans 11.3 has suddenly decided to change the format of try ... catch  blocks from:
        try {
            ...
        } catch (...) {
            ...
        }
to:
        try {
           ...
        }
        catch (...) {
           ...
        }

The latter is the style used by Oracle at:

However, Checkstyle is now complaining about the change.

Have we changed a project setting? I seem to remember some discussion of this topic recently but can't find it.

Dave


Bob Jacobsen
 

Look at Preferences -> Editor -> Formatting -> Java -> Alignment



Bob

On May 23, 2020, at 9:55 PM, Dave Heap <dgheap@...> wrote:

The "Format" command in NetBeans 11.3 has suddenly decided to change the format of try ... catch  blocks from:
        try {
            ...
        } catch (...) {
            ...
        }

to:
        try {
           ...
        }
        catch (...) {
           ...
        }

The latter is the style used by Oracle at:
<https://docs.oracle.com/javase/tutorial/essential/exceptions/try.html>

However, Checkstyle is now complaining about the change.

Have we changed a project setting? I seem to remember some discussion of this topic recently but can't find it.

Dave

--
Bob Jacobsen
rgj1927@...




danielb987
 

Go to menu item: Tools / Options. Select "Editor". Select the tab "Formatting". Select Language "Java" and Category "Alignment". There you have a checkbox "catch". Is that checkbox checked?

Daniel

2020-05-24 06:55 skrev Dave Heap:

The "Format" command in NetBeans 11.3 has suddenly decided to change
the format of try ... catch blocks from:
try {
...
} catch (...) {
...
}
to:
try {
...
}
catch (...) {
...
}
The latter is the style used by Oracle at:
<https://docs.oracle.com/javase/tutorial/essential/exceptions/try.html>
However, Checkstyle is now complaining about the change.
Have we changed a project setting? I seem to remember some discussion
of this topic recently but can't find it.
Dave
Links:
------
[1] https://jmri-developers.groups.io/g/jmri/message/3459
[2] https://groups.io/mt/74432823/1303822
[3] https://jmri-developers.groups.io/g/jmri/post
[4] https://jmri-developers.groups.io/g/jmri/editsub/1303822
[5] https://jmri-developers.groups.io/g/jmri/leave/defanged


Dave Heap
 

All,
On 24 May 2020, at 3:37 PM, danielb987 <db123@...> wrote:

There you have a checkbox "catch". Is that checkbox checked?

No, it's not checked. Something seems to be overriding that setting.

I'm suspecting:
merged since yesterday (my time zone).

What policy do we want?

I'm also suspecting this for suddenly aligning descriptions of @param in JavaDoc . I must say I like that one. Again, what policy do we want?

I'll hold off on a PR I was about to create...

Dave


Bob Jacobsen
 

I really hope that we can find the cause of this catch-line reformatting and kill it. K&R formatting was good enough for K&R, and I’ve become really accustomed to reading it.   

It’s in every standards doc I know of. I think perhaps somebody misinterpreted the page you referenced, which mentioned but doesn’t show catch blocks.  The next page ( https://docs.oracle.com/javase/tutorial/essential/exceptions/catch.html) does show them, and they’re in our old “Egyptian format”.

Could you also check the project properties?  Right-click on the JMRI project, select Properties, then Formatting, then alignment, then the catch checkbox?


Bob


On May 23, 2020, at 10:57 PM, Dave Heap <dgheap@...> wrote:

All,
On 24 May 2020, at 3:37 PM, danielb987 <db123@...> wrote:

There you have a checkbox "catch". Is that checkbox checked?

No, it's not checked. Something seems to be overriding that setting.

I'm suspecting:
<https://github.com/JMRI/JMRI/pull/8544/commits/70262a42f5368cb74f510df25a143461a134d10d>
merged since yesterday (my time zone).

What policy do we want?

I'm also suspecting this for suddenly aligning descriptions of @param in JavaDoc . I must say I like that one. Again, what policy do we want?

I'll hold off on a PR I was about to create...

Dave

--
Bob Jacobsen
rgj1927@...




danielb987
 

Test PR #8578. I think that will solve it.

https://github.com/JMRI/JMRI/pull/8578

Daniel

2020-05-24 08:50 skrev Bob Jacobsen:

I really hope that we can find the cause of this catch-line
reformatting and kill it. K&R formatting was good enough for K&R, and
I’ve become really accustomed to reading it.
It’s in every standards doc I know of. I think perhaps somebody
misinterpreted the page you referenced, which mentioned but doesn’t
show catch blocks. The next page (
https://docs.oracle.com/javase/tutorial/essential/exceptions/catch.html)
does show them, and they’re in our old “Egyptian format”.
Could you also check the project properties? Right-click on the JMRI
project, select Properties, then Formatting, then alignment, then the
catch checkbox?
Bob

On May 23, 2020, at 10:57 PM, Dave Heap <dgheap@...> wrote:
All,
On 24 May 2020, at 3:37 PM, danielb987 <db123@...> wrote:

There you have a checkbox "catch". Is that checkbox checked?
No, it's not checked. Something seems to be overriding that setting.
I'm suspecting:
<https://github.com/JMRI/JMRI/pull/8544/commits/70262a42f5368cb74f510df25a143461a134d10d>
merged since yesterday (my time zone).
What policy do we want?
I'm also suspecting this for suddenly aligning descriptions of
@param in JavaDoc . I must say I like that one. Again, what policy
do we want?
I'll hold off on a PR I was about to create...
Dave
--
Bob Jacobsen
@BobJacobsen
Links:
------
[1] https://jmri-developers.groups.io/g/jmri/message/3463
[2] https://groups.io/mt/74432823/1303822
[3] https://jmri-developers.groups.io/g/jmri/post
[4] https://jmri-developers.groups.io/g/jmri/editsub/1303822
[5] https://jmri-developers.groups.io/g/jmri/leave/defanged


Dave Heap
 

Bob,

On 24 May 2020, at 4:50 PM, Bob Jacobsen <rgj1927@...> wrote:

I really hope that we can find the cause of this catch-line reformatting and kill it. K&R formatting was good enough for K&R, and I’ve become really accustomed to reading it.   

Agreed.


It’s in every standards doc I know of. I think perhaps somebody misinterpreted the page you referenced, which mentioned but doesn’t show catch blocks.  The next page ( https://docs.oracle.com/javase/tutorial/essential/exceptions/catch.html) does show them, and they’re in our old “Egyptian format”.

I copied and pasted into my email from what I was sure was that page. Weird.

Could you also check the project properties?  Right-click on the JMRI project, select Properties, then Formatting, then alignment, then the catch checkbox?

I'll look later.

Dave


Dave Heap
 

Bob,

On 24 May 2020, at 6:10 PM, Dave Heap <dgheap@...> wrote:


It’s in every standards doc I know of. I think perhaps somebody misinterpreted the page you referenced, which mentioned but doesn’t show catch blocks.  The next page ( https://docs.oracle.com/javase/tutorial/essential/exceptions/catch.html) does show them, and they’re in our old “Egyptian format”.

I copied and pasted into my email from what I was sure was that page. Weird.

I wasn't imagining it. It was the previous page:

Dave


Dave Heap
 


Thanks Daniel.

Dave

On 24 May 2020, at 4:50 PM, Bob Jacobsen <rgj1927@...> wrote:

I really hope that we can find the cause of this catch-line reformatting and kill it. K&R formatting was good enough for K&R, and I’ve become really accustomed to reading it.


George Warner
 

This also started happening to me after I updated(¿) to NetB 11.3.
The checkboxes weren't checked but reformatting put catches on new lines.
I finally had to turn off "reformat on save" or otherwise I'd have to post edit externally (TGF BBEdit!) and restore all the catch block formatting.
So thanks for finding/fixing this! ;-)