I want to test a method which doesn’t return anything. The method starts by asserting that a parameter doesn’t contain an illegal value:
- (void) someMethod:(NSString*)param {
NSParamaterAssert(param != @"0");
// more code
}
In my testing code I want to make sure that illegal values are caught, but I don’t want the program exiting during testing. In python I can try: except: to catch it. Is there an equivalent in Objective C? Am I using assertions incorrectly here?
You are mixing up “Exceptions” and their “Handling” with assertions.
(Find more information on assertions here, “Exception Handling” is also on wikipedia but unfortunetaly I’m only allowed to post 2 links).
Assertions are normally not to be used as a way to preserve your method/program from (usually serious) errors (like wrong function behavior in special cases). Assertions are for example used with verification of programs.
You want to handle exceptions (like wrong parameters in your case).
A good starting point for doing so is here (ObjC only).