简体   繁体   中英

IntelliJ IDEA 13: Formatting Code Style for Java “throw new”

I'm using IntelliJ 13's "Code Style" feature to auto-format our Java code, but I can't figure out how to format throw new Exception("details") so that the "details" portion is on the same line as the throw new .

I want this:

if (connection == null) {
        throw new SQLException( "ERROR: Attempted to start a database transaction with a null connection." );

But I keep getting this after I type OPTION + COMMAND + L (on Mac) to apply the formatting:

if (connection == null) {
        throw new SQLException(
            "ERROR: Attempted to start a database transaction with a null connection." );

I've tried almost all the Code Style options under Project Settings > Code Style > Java > Wrapping and Braces but I can't seem to find the right setting.

Thanks for any help!

Alright, well it seems that IntelliJ is creating those line breaks because the contents of my "details" are sufficiently long. There appears to be a small bug where, after shortening the "details" String literal and then reapplying code styles, the line break does not revert.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM