我已經創建了子類NSException類來創建CustomException類。如何使用「超類的現有對象」初始化子類的對象目標C
每當我在代碼中捕獲異常(@catch)時,我想用作爲參數傳遞給@catch的NSException對象初始化CustomException(NSException的子類)對象。
像這樣的事情
@catch (NSException * e) {
CustomException * ex1=[[CustomException alloc]initWithException:e errorCode:@"-11011" severity:1];
}
我試圖通過傳遞NSException對象CustomException的init方法做這件事。 (我取代了[超級的init]與傳遞的NSException對象如下)
//initializer for CustomException
-(id) initWithException:(id)originalException errorCode: (NSString *)errorCode severity:(NSInteger)errorSeverity{
//self = [super initWithName: name reason:@"" userInfo:nil];
self=originalException;
self.code=errorCode;
self.severity=errorSeverity;
return self;
}
這doen't工作!我怎樣才能做到這一點?
在此先感謝
非常感謝!有用!早應該已經實現了這個 – TheBlackPearl 2011-02-02 11:06:02