Skip to content

AvoidHidingCauseException should detect constructor accepts a throwable #1085

@delanym

Description

@delanym

https://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/AvoidHidingCauseExceptionCheck.html

The check should ascertain whether the class indeed has a constructor that accepts a Throwable.

RuntimeException accepts a throwable, so catching the illegalstateexception and not including it in the runtime is a violation

     catch (IllegalStateException e) {
        throw new RuntimeException("Runtime Exception!");
      }

correct code is

     catch (IllegalStateException e) {
        throw new RuntimeException("Runtime Exception!", e);
      }

But some throwables do not allow you to create them with a cause exception/throwable, like the legacy ParseException
The constructor does not accept a throwable:

  public ParseException(String s, int errorOffset) {
    super(s);
    this.errorOffset = errorOffset;
  }

The rule should determine whether the exception actually accepts a cause exception before complaining about hiding the cause, since its impossible to construct the exception otherwise.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions