Skip to content

Flatten-Nested-Try

Sourcery rule id: flatten-nested-try

Description

Merge nested try-statement into a single try

Before

try {
    try {
        something()
    } catch (e) {
        catching()
    }
} finally {
    finalling()
}

After

try {
    something()
} catch (e) {
    catching()
} finally {
    finalling()
}

Explanation

Flattening try...catch statements nested within a try...finally generates equivalent code that is easier to read and expand upon.