【发布时间】:2013-10-13 13:39:12
【问题描述】:
我有以下代码。 . .
@try
{
NSArray * array = [[NSArray alloc] initWithObjects:@"1",@"2",nil];
// the below code will raise an exception
[array objectAtIndex:11];
}
@catch(NSException *exception)
{
// now i want to create a custom exception and throw it .
NSException * myexception = [[NSException alloc] initWithName:exception.name
reason:exception.reason
userInfo:exception.userInfo];
//now i am saving callStacksymbols to a mutable array and adding some objects
NSMUtableArray * mutableArray = [[NSMUtableArray alloc]
initWithArray:exception.callStackSymbols];
[mutableArray addObject:@"object"];
//but my problem is when i try to assign this mutable array to myexception i am getting following error
myexception.callStackSymbols = (NSArray *)mutableArray;
//error : no setter method 'setCallStackSymbols' for assignment to property
@throw myexception;
}
请帮助解决这个问题,我想在 callStackSymbols 中添加一些额外的对象。 . . .提前致谢
【问题讨论】:
-
不要尝试从异常中恢复。 iOS 和 OS X 中的异常应被视为不可恢复的致命程序员错误。
标签: ios objective-c try-catch throw nsexception