Skip to content

Files

Latest commit

 

History

History
33 lines (24 loc) · 802 Bytes

EmptyCatchBlock.md

File metadata and controls

33 lines (24 loc) · 802 Bytes

Pattern: Empty catch block

Issue: -

Description

Checks for empty catch blocks. In most cases, exceptions should not be caught and ignored (swallowed).

The rule has a property named ignoreRegex that defaults to the value ignore|ignored. If the name of the exception matches this regex then no violations are produced.

Examples:

def someMethod() {
    try {
        doSomething
    } catch(SomeException e) {                //violation
        // should do something here
    }
}

def someMethod() {
    try {
        doSomething
    } catch(SomeException ignored) {
        //no violations because the parameter name is ignored
    }
}

Further Reading