Skip to content

Class methods not handled #9

Description

@Alastor-git

Current behavior :

Here's a small example of exceptions not being handled in classes.

class MyClass {
    throwError() {
        throw new Error("test");
    }

    getError() {
        this.throwError();
        try {
            this.throwError();
        } catch {
            throw new Error("test");
        }
    }
    async throwErrorAsync() {
        throw new Error("test");
    }

    async getErrorAsync() {
        await this.throwErrorAsync();
        try {
            await this.throwErrorAsync();
        } catch {
            throw new Error("test");
        }
    }
}
const myClass = new MyClass();
myClass.getError();
myClass.getErrorAsync();

No error is pointed out.

Expected behavior :

  • Both throw new Error("test"); lines should warn about use-error-cause.
  • myClass.getError(); and myClass.getErrorAsync(); should warn about might-throw and no-unhandled.
  • this.throwError(); should warn about might-throw when not in a try statement.

Remarks:

try {
} catch (err) {
    throw new Error("test");
}

will warn about use-error-cause but the following will not :

try {
   throwError();
} catch {
    throw new Error("test");
}

However, the former is not rethrowing, when the latter is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions