Skip to content

Commit

Permalink
simplify Exception constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Jul 27, 2024
1 parent 41ad69d commit a1f1c2d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
53 changes: 33 additions & 20 deletions src/main/java/org/htmlunit/cssparser/parser/CSSException.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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;
}
Expand All @@ -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}
*
Expand All @@ -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;
}
}

/**
* <p>getCode.</p>
*
* @return the error code for this exception.
*/
public ErrorCode getCode() {
return code_;
return "syntax error";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a1f1c2d

Please sign in to comment.