Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TornadoException-s do not follow std. Java coding practices #167

Open
vsilaev opened this issue Dec 24, 2021 · 0 comments
Open

TornadoException-s do not follow std. Java coding practices #167

vsilaev opened this issue Dec 24, 2021 · 0 comments

Comments

@vsilaev
Copy link
Contributor

vsilaev commented Dec 24, 2021

TornadoRuntimeException, TornadoUnimplementedException, TornadoTaskRuntimeException, TornadoBailoutRuntimeException and probably others do not follow standard Java coding practices for Exception classes and contains redundant code.
For example, TornadoBailoutRuntimeException:

CURRENTLY:

public class TornadoBailoutRuntimeException extends RuntimeException {

    private final String message;
    private Exception e;
    static final String RESET = "\u001B[0m";
    static final String RED = "\u001B[31m";

    public TornadoBailoutRuntimeException(final String msg) {
        message = RED + msg + RESET;
    }

    public TornadoBailoutRuntimeException(final String msg, Exception e) {
        message = RED + msg + RESET;
        this.e = e;
    }

    public Exception getException() {
        return this.e;
    }

    @Override
    public String getMessage() {
        return message;
    }
}

SHOULD BE:

public class TornadoBailoutRuntimeException extends RuntimeException {

    static final String RESET = "\u001B[0m";
    static final String RED = "\u001B[31m";

    public TornadoBailoutRuntimeException(final String msg) {
        super(RED + msg + RESET);
    }

    public TornadoBailoutRuntimeException(final String msg, Exception e) {
        super(RED + msg + RESET, e);
    }

    // May be removed as well - because it's a synonim for getCause()
    public Throwable getException() {
        return getCause();
    }

}

The fixed version is not only more compact, but prints exception traces correctly, because the chain of exceptions is initialized (unlike it's done currently).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant