Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSException raise:format: as the last statement in a method

I have this method:

+ (MHTwitterParser*)createParser:(NSString*)format {
    if ([format compare:@"json"] == NSOrderedSame) {
        return [[MHJsonTwitterParser alloc] init];
    }

    [NSException raise:@"Unknown format" format:@"Unknown format of parser"];
}

Compiler complains that:

Control may reach end of non-void function

It is just a warning, but it does not matter.

Obvious fix for that is to add for example return nil; after the [NSException raise: ....

However, I think it is not needed (and is even misleading for readers), because the exception is thrown, so it is not true that "Control may reach end of non-void function". Or am I missing something ...? Is it only compiler imperfection or there is some considerable reason for this?

The compiler is Apple LLVM compiler 3.1

like image 658
Ondrej Peterka Avatar asked Nov 30 '22 06:11

Ondrej Peterka


1 Answers

Replacing [exception raise]; with @throw exception; is functionally the same thing and will prevent the warning (see: Throwing Exceptions).

like image 123
Jeffery Thomas Avatar answered Dec 04 '22 06:12

Jeffery Thomas