NSExceptionクラスをサブクラス化して、CustomExceptionクラスを作成しました。
コード(@catch内)で例外をキャッチするたびに、CustomExceptionのオブジェクト(NSExceptionのサブクラス)を、パラメーターとして@catchに渡されるNSExceptionのオブジェクトで初期化します。
このようなもの
@catch (NSException * e) {
CustomException * ex1=[[CustomException alloc]initWithException:e errorCode:@"-11011" severity:1];
}
NSExceptionオブジェクトをCustomExceptionのinitメソッドに渡してみました。([super 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;
}
これは機能しません!どうすればこれを達成できますか?
前もって感謝します