From a1f1c2d61e6ecde0764097d71329700354e177b9 Mon Sep 17 00:00:00 2001 From: Ronald Brill Date: Sat, 27 Jul 2024 16:35:29 +0200 Subject: [PATCH] simplify Exception constructors --- .../cssparser/parser/CSSException.java | 53 ++++++++++++------- .../cssparser/parser/CSSParseException.java | 2 +- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/htmlunit/cssparser/parser/CSSException.java b/src/main/java/org/htmlunit/cssparser/parser/CSSException.java index a451582..8030bb7 100644 --- a/src/main/java/org/htmlunit/cssparser/parser/CSSException.java +++ b/src/main/java/org/htmlunit/cssparser/parser/CSSException.java @@ -19,7 +19,12 @@ */ public class CSSException extends RuntimeException { - /** Enum for error codes. */ + /** + * Enum for error codes. + * + * @deprecated as of version 4.4.0 + */ + @Deprecated protected enum ErrorCode { /** Unspecified. */ UNSPECIFIED_ERR, @@ -34,14 +39,20 @@ protected enum ErrorCode { /** * Creates a new CSSException. + * + * @deprecated as of version 4.4.0; use {@link CSSException#CSSException(String, Exception)} instead */ + @Deprecated public CSSException() { } /** * Creates a new CSSException. * @param message the message + * + * @deprecated as of version 4.4.0; use {@link CSSException#CSSException(String, Exception)} instead */ + @Deprecated public CSSException(final String message) { code_ = ErrorCode.UNSPECIFIED_ERR; message_ = message; @@ -50,7 +61,10 @@ public CSSException(final String message) { /** * Creates a new CSSException with an embeded exception. * @param e the embeded exception. + * + * @deprecated as of version 4.4.0; use {@link CSSException#CSSException(String, Exception)} instead */ + @Deprecated public CSSException(final Exception e) { code_ = ErrorCode.UNSPECIFIED_ERR; initCause(e); @@ -59,7 +73,10 @@ public CSSException(final Exception e) { /** * Creates a new CSSException with a specific code. * @param code a the embeded exception. + * + * @deprecated as of version 4.4.0; use {@link CSSException#CSSException(String, Exception)} instead */ + @Deprecated public CSSException(final ErrorCode code) { code_ = code; } @@ -70,13 +87,27 @@ public CSSException(final ErrorCode code) { * @param code the specified code * @param message the message * @param e the embeded exception + * + * @deprecated as of version 4.4.0; use {@link CSSException#CSSException(String, Exception)} instead */ + @Deprecated public CSSException(final ErrorCode code, final String message, final Exception e) { code_ = code; message_ = message; initCause(e); } + /** + * Creates a new CSSException with an embeded exception and a specified + * message. + * @param message the message + * @param e the cause + */ + public CSSException(final String message, final Exception e) { + message_ = message; + initCause(e); + } + /** * {@inheritDoc} * @@ -95,24 +126,6 @@ public String getMessage() { return getCause().getMessage(); } - switch (code_) { - case UNSPECIFIED_ERR: - return "unknown error"; - case NOT_SUPPORTED_ERR: - return "not supported"; - case SYNTAX_ERR: - return "syntax error"; - default: - return null; - } - } - - /** - *

getCode.

- * - * @return the error code for this exception. - */ - public ErrorCode getCode() { - return code_; + return "syntax error"; } } diff --git a/src/main/java/org/htmlunit/cssparser/parser/CSSParseException.java b/src/main/java/org/htmlunit/cssparser/parser/CSSParseException.java index a948f1d..8a5391e 100644 --- a/src/main/java/org/htmlunit/cssparser/parser/CSSParseException.java +++ b/src/main/java/org/htmlunit/cssparser/parser/CSSParseException.java @@ -99,7 +99,7 @@ public CSSParseException(final String message, final String uri, final int lineN */ public CSSParseException(final String message, final String uri, final int lineNumber, final int columnNumber, final Exception e) { - super(ErrorCode.SYNTAX_ERR, message, e); + super(message, e); uri_ = uri; lineNumber_ = lineNumber; columnNumber_ = columnNumber;