@try block is empty

ID

objectivec.correctness.empty_try_block

Severity

low

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

low

Resource

Error Handling

Language

Objective-C

Description

Reports an @try whose body holds nothing at all, whether the braces are written on one line or across several. A body carrying a statement or an explanatory comment is not reported.

Rationale

An @try guarding nothing cannot raise, so the @catch attached to it is unreachable and the @finally runs unconditionally. That is the shape left behind when the guarded call is moved or deleted: the handler survives, still looks like error handling, and now protects nothing. Readers and reviewers trust it, and the call that actually can raise ends up somewhere outside the block.

The following code illustrates the pattern detected by this rule:

@implementation Importer
- (void)importOnOneLine {
    // FLAGGED: @try block is empty
    @try { } @catch (NSException *e) {
        NSLog(@"%@", e.reason);
    }
}

- (void)parse {
    NSLog(@"parsing");
}

- (void)close {
    NSLog(@"closing");
}
@end

Remediation

Move the call that can raise back inside the @try, or delete the whole construct and keep only the statements that remain. If the @finally cleanup is the part still worth having, express it directly rather than through an exception handler that guards an empty body.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved